1.实现步骤
使用 uiautomation 找到微信窗口并监控
模拟点击消息 循环获取 群对话最后一条
获取后调用成语接龙api 获取接龙成果后 使用pyperclip 复制粘贴 发送消息
import random
import uiautomation as ui
import pyperclip
import requests
wx = ui.WindowControl(Name = "微信")
wx.SwitchToThisWindow()
hw = wx.ListControl(Name = "会话")
we = hw.TextControl(searchDepth=4)
we.Click(simulateMove=False)
kk= 0
ddd = []
while True:
last_msg = wx.ListControl(Name = "消息").GetChildren()[-1].Name
print(last_msg)
# last_msg= "第3条:百战百胜"
if last_msg:
if "条:" in last_msg:
ddd = []
print("*****************")
ll = []
cheng = last_msg.split("条:")[-1]
cheng = cheng.replace("👈","")
cheng = cheng.replace("👉", "")
res = requests.get("https://www.cyjl123.com/api/web/detail?word={}".format(str(cheng)))
res = res.json()
for i in range(int(len(res["result"]["candidate"]))):
res_cheng = res["result"]["candidate"][i]["word"]
ll.append(res_cheng)
# input = int(input("其他跳过,1选择成语: "))
# if input == 1:
print(ll)
if ll == []:
continue
# res_ll = ll[0]
res_ll = random.choice(ll)
pyperclip.copy(res_ll)
wx.SendKeys("{Ctrl}v", waitTime=0)
wx.SendKeys("{Enter}", waitTime=0)
ddd = ll
elif "这不是成语" in last_msg:
kk+=1
if ddd == []:
continue
try:
res_ll = ddd[kk]
except:
continue
pyperclip.copy(res_ll)
wx.SendKeys("{Ctrl}v", waitTime=0)
wx.SendKeys("{Enter}", waitTime=0)