python实现微信自动回复

python实现微信自动回复,第1张

由于网页版微信取消后,无法再使用itchat,这里说明通用版本的自动回复

源码:

import uiautomation
import time
# from translate import Translator



class Wechat():
    def __init__(self):
        """定义窗口名
           获取窗口句柄
        """
        self.windows_name = '阵雨'
        self.window = uiautomation.WindowControl(searchDepth=1,Name=self.windows_name)
        # self.tran_to_chinese = Translator(to_lang='chinese')
        #
        # self.tran_to_english = Translator(to_lang='english')


    def get_msg_list(self):
        """检测窗口的list并获取句柄"""
        msg_list = []
        msg_strl_list = self.window.ListControl().GetChildren()
        for msg_ctrl in msg_strl_list:
            msg_list.append(msg_ctrl.Name)
        return msg_list

    def send_text_msg(self,text_msg):
        self.window.SendKeys(text_msg)
        # 写入消息

        self.window.SendKey(13)
        # 发送


    # def auto_translate(self,input_content):
    #     """判断是否中文"""
    #
    #     for latter in input_content:
    #         if '\u4e00' <= latter <= '\u9fff':
    #             return self.tran_to_english.translate(input_content)
    #         else:
    #             return self.tran_to_chinese.translate(input_content)

    def former_msg_list(self):
        "上一条消息"
        last_list = self.get_msg_list()
        return last_list

if __name__ == '__main__':
    test = Wechat()
    while True:
        latest_msg_list = test.get_msg_list()
        former_list = test.former_msg_list()
        if latest_msg_list != former_list:
            new_msg = latest_msg_list[-1]
            test.send_text_msg(text_msg='我现在有事不在,请待会联系')
            former_list = test.get_msg_list()
            time.sleep(1)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/755831.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-30
下一篇 2022-04-30

发表评论

登录后才能评论

评论列表(0条)

保存