-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path闲鱼任务.py
347 lines (335 loc) · 15.3 KB
/
闲鱼任务.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import time
import uiautomator2 as u2
from utils import get_current_app, fish_not_click, find_button, find_text_position
import ddddocr
d = u2.connect()
d.app_start("com.taobao.idlefish", stop=True, use_monkey=True)
screen_width, screen_height = d.window_size()
ctx = d.watch_context()
ctx.when("暂不升级").click()
ctx.when("放弃").click()
ctx.when("确定").click()
ctx.start()
have_clicked = dict()
error_count = 0
ocr = ddddocr.DdddOcr(show_ad=False)
finish_count = 0
def click_earn():
while True:
throw_btn = d(className="android.view.View", resourceId="mapDiceBtn")
if throw_btn.exists:
d.click(throw_btn[0].bounds()[2] + 50, throw_btn[0].center()[1] + 30)
time.sleep(5)
if d(className="android.view.View", resourceId="taskWrap").exists:
break
time.sleep(2)
def back_to_ad():
while True:
_, activity = get_current_app(d)
if activity == "com.taobao.idlefish.ads.ylh.YlhPortraitADActivity":
break
d.press("back")
time.sleep(0.2)
def back_to_task():
print("开始返回到闲鱼币首页。")
while True:
if d(className="android.webkit.WebView", text="闲鱼币首页").exists:
print("当前是闲鱼币首页,不能继续返回")
break
else:
pt = find_button(d.screenshot(format='opencv'), "./img/fish_back.png", (0, 0, 100, 200))
if pt:
d.click(int(pt[0]) + 8, int(pt[1]) + 10)
else:
d.press("back")
time.sleep(0.1)
def operate_task():
_, activity = get_current_app(d)
if activity == "com.taobao.idlefish.ads.ylh.YlhPortraitADActivity":
print("第一种情况:去微信看短剧或点击广告看详情")
while True:
click_btn = d(className="android.widget.TextView", textContains="点击广告")
if click_btn.exists:
detail_btn = d(className="android.widget.TextView", text="查看详情")
if detail_btn.exists:
d.click(detail_btn[0].center()[0], detail_btn[0].center()[1])
time.sleep(5)
back_to_ad()
image = d.screenshot(format='opencv')
pt = find_button(image, "./img/fish_close.png")
if pt:
d.click(int(pt[0]) + 5, int(pt[1]) + 5)
time.sleep(2)
break
wechat_btn = d(className="android.widget.TextView", text="去微信看短剧")
if wechat_btn.exists:
d.click(wechat_btn[0].center()[0], wechat_btn[0].center()[1])
time.sleep(20)
back_to_ad()
continue
wechat_btn = d(className="android.widget.TextView", text="去微信继续看")
if wechat_btn.exists:
d.click(wechat_btn[0].center()[0], wechat_btn[0].center()[1])
time.sleep(8)
back_to_ad()
continue
wechat_btn = d(className="android.widget.TextView", text="去微信看全集")
if wechat_btn.exists:
image = d.screenshot(format='opencv')
pt = find_button(image, "./img/fish_close.png")
if pt:
d.click(int(pt[0]) + 5, int(pt[1]) + 5)
time.sleep(2)
break
elif activity == "com.taobao.idlefish.ads.csj.TTAdStandardPortraitActivity":
print("第二种情况:我要直接拿奖励")
while True:
direct_btn = d(className="android.widget.TextView", text="我要直接拿奖励")
if direct_btn.exists:
d.click(direct_btn[0].center()[0], direct_btn[0].center()[1])
time.sleep(20)
break
detail_btn = d(className="android.widget.TextView", text="查看详情")
if detail_btn.exists:
print("点击查看详情,跳转app。")
d.click(detail_btn[0].center()[0], detail_btn[0].center()[1])
time.sleep(5)
break
time_div = d(className="android.widget.TextView", textMatches=r"\d+s")
if time_div.exists:
time.sleep(int(time_div[0].get_text().replace("s", "")) + 3)
break
time.sleep(3)
back_to_task()
else:
if d(className="android.widget.TextView", textMatches=r"继续浏览\d+s获1个骰子").exists:
print("首页滑动,开始模拟滑动")
start_time = time.time()
while True:
if time.time() - start_time > 15:
break
d.swipe_ext("up", scale=0.2)
time.sleep(1)
d(scrollable=True).fling.vert.toBeginning(max_swipes=1000)
time.sleep(2)
click_earn()
elif d(className="android.webkit.WebView", text="闲鱼币首页").exists:
return
elif d(className="android.widget.TextView", text="我的夺宝").exists:
print("我的夺宝页面...")
treasures_btn = d(className="android.widget.TextView", text="我的夺宝")
if treasures_btn.exists:
d.click(screen_width / 2, treasures_btn[0].bounds()[3] + 20)
time.sleep(2)
red_btn = d(className="android.widget.TextView", textMatches=r"获得\d+个红包.*")
if red_btn.exists:
d.click(red_btn[0].bounds()[2] - 20, red_btn[0].center()[1])
time.sleep(3)
pt = find_button(d.screenshot(format='opencv'), "./img/fish_open.png")
print(f"查找到一键开启按钮结果:{pt}")
if pt:
d.click(int(pt[0]) + 5, int(pt[1]) + 5)
time.sleep(2)
while True:
if d(className="android.widget.TextView", text="我的夺宝").exists:
break
d.press("back")
time.sleep(0.2)
take_part_btn = d(className="android.widget.TextView", textContains="500币")
if take_part_btn.exists:
d.click(take_part_btn[0].center()[0], take_part_btn[0].center()[1])
time.sleep(2)
pt = find_button(d.screenshot(format='opencv'), "./img/fish_confirm_attend.png")
if pt:
d.click(screen_width / 2, int(pt[1]) + 20)
time.sleep(2)
back_to_task()
elif d(className="android.webkit.WebView", text="好物夺宝").exists:
print("好物夺宝页面...")
# re_btn = d(className="android.widget.Image", text="TB1NMQKL7voK1RjSZPfXXXPKFXa-112-78")
treasures_btn = d(className="android.widget.TextView", textContains="闲鱼币夺宝")
if treasures_btn.exists:
d.click(treasures_btn[0].center()[0], treasures_btn[0].center()[1])
time.sleep(4)
treasures_btn = d(className="android.widget.TextView", textContains="闲鱼币夺宝")
d.click(treasures_btn[0].center()[0], treasures_btn[0].center()[1])
time.sleep(2)
reduce_btn = d(className="android.widget.Image", text="O1CN01FnFgEu1pxA2fVZtOh_!!6000000005426-0-tps-330-330")
if reduce_btn.exists:
d.click(reduce_btn[0].center()[0], reduce_btn[0].center()[1])
time.sleep(1)
d.click(reduce_btn[0].center()[0], reduce_btn[0].center()[1])
time.sleep(1)
bet_btn = d(className="android.widget.TextView", text="确定投注")
if bet_btn.exists:
bet_btn.click()
time.sleep(2)
tou_btn = d(className="android.widget.TextView", text="直接投1注")
if tou_btn.exists:
d.click(tou_btn[0].center()[0], tou_btn[0].center()[1])
time.sleep(2)
back_to_task()
elif d(className="android.webkit.WebView", text="红包签到").exists:
print("红包签到页面...")
ball_btn = d(className="android.widget.View", resourceId="wingBallId")
if ball_btn.exists:
d.click(ball_btn[0].center()[0], ball_btn[0].center()[1])
time.sleep(2)
back_to_task()
else:
advert_text = d(className="android.widget.TextView", textContains="广告")
if advert_text.exists:
print("看广告领取奖励页面")
while True:
touch_btn = d(className="android.widget.TextView", text="点击广告可领取奖励")
if touch_btn.exists:
download_btn = d(className="android.widget.TextView", text="立即下载")
if download_btn.exists:
d.click(50, download_btn[0].center()[1])
time.sleep(5)
back_to_task()
break
time.sleep(3)
else:
print("普通页面")
search_view = d(className="android.view.View", text="搜索有福利")
search_edit = d(resourceId="com.taobao.taobao:id/searchEdit")
search_btn = d(resourceId="com.taobao.taobao:id/searchbtn")
if search_view.exists and d(className="android.widget.Button", text="搜索").exists:
d(className="android.widget.EditText", instance=0).send_keys("笔记本电脑")
d(className="android.widget.Button", text="搜索").click()
time.sleep(2)
elif search_edit.exists and search_btn.exists:
search_edit.send_keys("笔记本电脑")
search_btn.click()
time.sleep(2)
start_time = time.time()
print("开始上下滑动")
while True:
d.swipe_ext(u2.Direction.FORWARD)
time.sleep(1)
d.swipe_ext(u2.Direction.BACKWARD)
time.sleep(1)
if time.time() - start_time > 28:
break
print("滑动完毕,开始退出")
back_to_task()
time.sleep(5)
ctx.wait_stable()
while True:
sign_btn1 = d(resourceId="com.taobao.idlefish:id/icon_entry_lottie", className="android.widget.ImageView", clickable=True)
sign_btn2 = d(className="android.widget.ImageView", resourceId="com.taobao.idlefish:id/icon_entry")
print(f"查找签到按钮,存在:{sign_btn1.exists}, {sign_btn2.exists}")
if sign_btn1.exists:
d.click(sign_btn1.center()[0], sign_btn1.center()[1])
time.sleep(2)
elif sign_btn2.exists:
d.click(sign_btn2.center()[0], sign_btn2.center()[1])
time.sleep(2)
if d(className="android.webkit.WebView", text="闲鱼币首页").exists:
break
time.sleep(1)
time.sleep(6)
if not d(className="android.view.View", resourceId="taskWrap").exists:
click_earn()
while True:
try:
print("正在查找按钮...")
time.sleep(4)
sign_btn = d(className="android.widget.TextView", text="签到", clickable=True)
if sign_btn.exists:
sign_btn.click()
time.sleep(4)
receive_btn = d(className="android.widget.TextView", text="领取奖励", clickable=True)
if receive_btn.exists:
receive_btn.click()
print("点击领取奖励")
time.sleep(2)
finish_count = finish_count + 1
if finish_count % 5 == 0:
d.swipe_ext("up", scale=0.2)
time.sleep(4)
continue
to_btn = d(className="android.widget.TextView", text="去完成", clickable=True)
if to_btn.exists:
need_click_view = None
task_name = None
for btn in to_btn:
print("开始识别...")
screen_shot = d.screenshot()
cropped_rect = (200, btn.bounds()[1] - 50, btn.bounds()[0] - 50, btn.bounds()[1] + 30)
cropped_image = screen_shot.crop(cropped_rect)
task_name = ocr.classification(cropped_image)
print(f"识别成功:{task_name}")
if fish_not_click(task_name):
continue
need_click_view = btn
break
if need_click_view and task_name:
d.double_click(need_click_view.center()[0], need_click_view.center()[1])
print(f"点击按钮{task_name}")
if have_clicked.get(task_name) is None:
have_clicked[task_name] = 1
else:
have_clicked[task_name] += 1
time.sleep(8 if "视频" in task_name else 3)
operate_task()
else:
print("未找到可点击按钮", error_count)
break
except Exception as e:
print("未找到可点击按钮", error_count)
break
print(f"共自动化完成{finish_count}个任务")
task_close_btn = d(resourceId="taskWrap", className="android.view.View").child(className="android.widget.TextView", index=0)
if task_close_btn.exists:
print("点击关闭任务列表")
d.click(task_close_btn.center()[0], task_close_btn.center()[1])
time.sleep(1)
receive_btn2 = d(className="android.widget.TextView", resourceId="dailyRewardBox")
if receive_btn2.exists:
print("点击领取奖励")
d.click(receive_btn2[0].center()[0], receive_btn2[0].center()[1])
time.sleep(2)
throw_btn = d(className="android.view.View", resourceId="mapDiceBtn")
while True:
print("开始摇骰子...")
count_btn = throw_btn.child(className="android.widget.TextView", index=0)
if count_btn.exists:
print(f"摇骰子次数:{count_btn.get_text()}")
numbers = filter(str.isdigit, count_btn.get_text())
if len(numbers) <= 0:
break
count = int(''.join(numbers))
if count > 0:
d.click(throw_btn.center()[0], throw_btn.center()[1])
time.sleep(5)
draw_btn = d(className="android.widget.TextView", text="开始抽奖")
if draw_btn.exists:
d.click(draw_btn.center()[0], draw_btn.center()[1])
time.sleep(10)
in_btn = d(className="android.widget.TextView", text="收下礼物")
if in_btn.exists:
d.click(in_btn.center()[0], in_btn.center()[1])
time.sleep(3)
continue
screen_image = d.screenshot(format='opencv')
pt1 = find_button(screen_image, "./img/fish_advance.png")
if pt1:
d.click(int(pt1[0]) + 50, int(pt1[1]) + 20)
time.sleep(3)
continue
pt2 = find_button(screen_image, "./img/fish_continue.png")
if pt2:
d.click(int(pt2[0]) + 50, int(pt2[1]) + 20)
time.sleep(3)
continue
pt3 = find_button(screen_image, "./img/fish_continue2.png")
if pt3:
d.click(int(pt3[0]) + 50, int(pt3[1]) + 20)
time.sleep(3)
continue
else:
break
time.sleep(2)
ctx.stop()