-
Notifications
You must be signed in to change notification settings - Fork 1
/
WeChat_Android.py
65 lines (47 loc) · 1.64 KB
/
WeChat_Android.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# !/usr/bin/env python
# -*- encoding: utf-8 -*-
# @File: WeChat.py
# @Time: 2021/02/11 07:32:20
# @Author: Max
import uiautomator2 as u2
import time
import random
from tqdm import tqdm
def sleep(s):
time.sleep(s)
def read_txt(txt_path):
with open(txt_path, 'r', encoding='utf-8') as f:
data = f.readlines()
data = list(map(lambda x: x.rstrip('\n'), data))
return data
data = read_txt('bless.txt')
names = read_txt('assets/friend_name.txt')
d = u2.connect('192.168.31.191')
print(d.info)
print('打开微信')
d.app_start('com.tencent.mm')
# 点击搜索
d.xpath('//*[@resource-id="com.tencent.mm:id/he6"]').click()
for name in tqdm(names):
info = random.choice(data)
# 输入内容
d.xpath('//*[@resource-id="com.tencent.mm:id/fdi"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]').click()
d.send_keys(name, clear=True)
sleep(0.3)
# 点击第一个人
d.xpath('//*[@resource-id="com.tencent.mm:id/hf1"]/android.widget.RelativeLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]').click()
sleep(0.2)
# 获取当前好友名称
friend_name = d(resourceId="com.tencent.mm:id/ipt").get_text()
# 输入内容
d(resourceId="com.tencent.mm:id/iki").click()
info = f"{friend_name},过年好啊!我在这里给您拜年了,{info}[烟花][烟花][烟花]"
d.send_keys(info, clear=True)
sleep(0.3)
# 点击发送
d(resourceId="com.tencent.mm:id/ay7").click()
sleep(0.5)
# 点击返回
d(resourceId="com.tencent.mm:id/un").click()
sleep(0.3)
print('运行完毕')