微信自动回复,再也不要早上起来回消息

import uiautomation as auto
import numpy as np
import pandas as pd
import re
if __name__=="__main__":
    wechatWindow = auto.WindowControl(searchDepth=1, Name="微信", ClassName='WeChatMainWndForPC')
    if wechatWindow.SetFocus():  # 正确返回self.Element.SetFocus() 错误返回False
        session = wechatWindow.ListControl(Name="会话")
        we = session.TextControl(searchDepth=4)#深度为4
        while True:
            if we.Exists():
                wechatWindow.ListControl()#
                wechatWindow.SwitchToThisWindow()
                df = pd.read_csv('回复数据.csv', encoding='utf-8')# 通过pd读取数据
                we.Click(simulateMove=False)# 点击未读消息
                last_msg = wechatWindow.ListControl(Name='消息').GetChildren()[-1].Name# 读取最后一条消息
                # 判断关键字,#axis按行应用函数 默认0按列
                msg = df.apply(lambda x: x['回复内容'] if x['关键词'] in last_msg else None, axis=1)
                #如果last_msg有关键词则x=回复内容,没有的则变成
                # 数据筛选,移除空数据
                msg.dropna(axis=0, how='any', inplace=True)#axis=0时,删除有空值的那一行 how='all'则删除空值的行和列
                ar = np.array(msg).tolist()#做成列表
                # 能够匹配到数据时
                if ar:
                    # 发送消息 回车键
                    wechatWindow.SendKeys(ar[0],waitTime=0)
                    wechatWindow.SendKeys('{Enter}', waitTime=0)
                # 没有匹配到数据时
                else:
                    wechatWindow.SendKeys('我不理解你什么意思', waitTime=1)
                    wechatWindow.SendKeys('{Enter}', waitTime=0)
                wechatWindow.ButtonControl(Name="最小化" ).Click()

回复数据.csv里面的内容
序号,关键词,回复内容
1,早上好,早上好,我在吃早餐

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值