forked from Sjj1024/QiangCai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meituan.py
126 lines (105 loc) · 3.46 KB
/
meituan.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import os
import platform
import time
import threading
import uiautomator2 as u2
# 连接手机
def connect_phone(device_name):
d = u2.connect(device_name)
if not d.uiautomator.start():
# 启动uiautomator服务
print("start uiautomator")
d.uiautomator.start()
time.sleep(2)
return d
def play_voice(content):
"""
播放声音提醒
"""
from playsound import playsound
root_path = os.getcwd()
video_path = os.path.join(root_path, "sources", "videos", f"{content}.mp3")
threading.Thread(target=playsound, args=(video_path,)).start()
def qiang_cai(device_name):
d = connect_phone(device_name)
d.app_start("com.sankuai.meituan")
count = 1
time_start = time.time()
while True:
start = time.time()
if d(textContains="结算(").exists:
print("点击结算")
d(textContains="结算(").click()
else:
print("点击全选")
if d(text="全选").exists:
print("点击全选")
d(text="全选").click()
if d(text="我知道了").exists:
print("点击我知道了")
d(text="我知道了").click()
if d(text="重新加载").exists:
print("重新加载")
d(text="重新加载").click()
if d(text="返回购物车").exists:
print("点击返回购物车")
d(text="返回购物车").click()
if d(text="立即支付").exists:
print("点击立即支付")
play_voice("success")
d(text="立即支付").click()
if d(text="确认并支付").exists:
print("点击确认并支付")
play_voice("success")
d(text="确认并支付").click()
if d(textContains="极速支付").exists:
print("极速支付")
play_voice("success")
break
if d(textContains="普通支付").exists:
print("普通支付")
play_voice("success")
break
if d(resourceId="btn-line").exists:
play_voice("success")
print("确认支付")
d(resourceId="btn-line").click()
break
print("本次花费时间:", time.time() - start)
print("总共花费时间:", (time.time() - time_start) / 60, "分钟,第", count, "次")
count += 1
def is_mac():
system = platform.system()
if system == "Windows":
print("当前系统是Windows")
return False
else:
print("当前系统是Mac")
return True
def get_device_list():
root_path = os.getcwd()
if is_mac():
cmd = os.path.join(root_path, "sources", "mac_tools", "adb devices")
else:
cmd = os.path.join(root_path, "sources", "win_tools", "adb.exe devices")
res = os.popen(cmd).read()
print(f"adb 命令结果是:\n{res}")
list_phone = [i for i in res.split("\n") if i]
if len(list_phone) > 1:
phone_num = [i.split("\t")[0] for i in list_phone[1:] if i]
print(f"得到的设备列表是:{phone_num}")
return phone_num
def run(device_name):
play_voice("start")
print("开始执行抢菜程序.....")
while True:
try:
qiang_cai(device_name)
except Exception as e:
print(e)
play_voice("error")
time.sleep(5)
if __name__ == '__main__':
# 修改为设备编码
device_name = "RFCN309ABWX"
run(device_name)