complete_browse.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. """
  2. 懂车帝
  3. 完整养号
  4. """
  5. import random
  6. import time
  7. from func.action_func import del_key_vague
  8. from scene.oprator.atom_data import single_click_by_control, swipe_screen, single_click_by_text, start_app
  9. from task.task_job import callback_task
  10. from tools import loggerKit, redis_client
  11. def complete_browse(task_id, device_id, data):
  12. loggerKit.info('请求信息:{0}'.format(data))
  13. device_id = data.get("deviceID")
  14. perform_action_id = data.get("performActionId")
  15. result = data.get("result")
  16. inner_data = data.get("data")
  17. keyword = inner_data.get("resourceName")
  18. loggerKit.info("inner_data:{0}, keyword:{1}", inner_data, inner_data.get("resourceName"))
  19. if result is not None:
  20. """
  21. 非首个指令
  22. """
  23. perform_action_result = result.get("performActionResult")
  24. if perform_action_result is None:
  25. return_dict = {
  26. "data": "",
  27. "code": -2,
  28. "message": "fail, performActionResult is null"
  29. }
  30. # 回调任务中心
  31. del_key_vague(device_id)
  32. callback_task(500, '指令执行失败', task_id, device_id, 0, None)
  33. return return_dict
  34. # 指令执行失败
  35. if perform_action_result == "failure":
  36. # 回调任务中心
  37. return_dict = {
  38. "data": "",
  39. "code": -2,
  40. "message": "fail, performActionResult is null"
  41. }
  42. del_key_vague(device_id)
  43. callback_task(500, '指令执行失败', task_id, device_id, 0, None)
  44. return return_dict
  45. # 终止指令
  46. if perform_action_result == "stop":
  47. # 回调任务中心
  48. return_dict = {
  49. "data": "",
  50. "code": -2,
  51. "message": "指令被用户终止"
  52. }
  53. del_key_vague(device_id)
  54. callback_task(500, '指令被用户终止', task_id, device_id, 0, None)
  55. return return_dict
  56. # 终止指令
  57. if perform_action_result == "eleNotFound":
  58. # 回调任务中心
  59. return_dict = {
  60. "data": "",
  61. "code": -2,
  62. "message": "未找到签到指示"
  63. }
  64. del_key_vague(device_id)
  65. callback_task(500, '未找到签到指示,该账号当天可能已经签到过', task_id, device_id, 0, None)
  66. return return_dict
  67. last_action_id = redis_client.get(device_id + "operate")
  68. step0 = redis_client.get(f"{device_id}_step0")
  69. if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  70. last_action_id) and perform_action_result == "success":
  71. action1_id = int(round(time.time() * 1000))
  72. """
  73. 发送第1条指令
  74. 首页下拉刷新
  75. """
  76. action1_dict = swipe_screen(action1_id, scale=0.5, timeout=30, direction="down")
  77. redis_client.set(device_id + "operate", action1_id)
  78. redis_client.set(f"{device_id}_step1", "1")
  79. redis_client.delete(f"{device_id}_step0")
  80. loggerKit.info("设备:{0}, action1_id:{1}", device_id, action1_id)
  81. return action1_dict
  82. """
  83. 每次操作完成后会将对应的操作唯一id存储到redis
  84. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  85. """
  86. last_action_id = redis_client.get(device_id + "operate")
  87. step1 = redis_client.get(f"{device_id}_step1")
  88. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  89. last_action_id) and perform_action_result == "success":
  90. action2_id = int(round(time.time() * 1000))
  91. """
  92. 发送第2条指令
  93. 在首页随机滑动2~3屏
  94. """
  95. random_scale = random.randint(1, 3)
  96. action2_dict = swipe_screen(action2_id, scale=random_scale, timeout=30)
  97. redis_client.set(device_id + "operate", action2_id)
  98. redis_client.set(f"{device_id}_step2", "1")
  99. redis_client.delete(f"{device_id}_step1")
  100. loggerKit.info("设备:{0}, action2_id:{1}", device_id, action2_id)
  101. return action2_dict
  102. """
  103. 点击关键词搜索框
  104. """
  105. step2 = redis_client.get(f"{device_id}_step2")
  106. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  107. last_action_id) and perform_action_result == "success":
  108. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  109. action3_id = int(round(time.time() * 1000))
  110. """
  111. 发送第3条指令
  112. 点击进入帖子
  113. """
  114. action3_dict = single_click_by_control(action3_id, control_id="com.ss.android.auto:id/jum",
  115. control_ids="com.ss.android.auto:id/s,com.ss.android.auto:id/k2k,"
  116. "com.ss.android.auto:id/p")
  117. redis_client.set(device_id + "operate", action3_id)
  118. redis_client.set(f"{device_id}_step3", "1")
  119. redis_client.delete(f"{device_id}_step2")
  120. loggerKit.info("设备:{0}, action2_id:{1}", device_id, action3_id)
  121. return action3_dict
  122. """
  123. 输入关键词
  124. """
  125. step3 = redis_client.get(f"{device_id}_step3")
  126. if step3 is not None and int(step3) == 1 and last_action_id is not None and int(perform_action_id) == int(
  127. last_action_id) and perform_action_result == "success":
  128. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  129. action4_id = int(round(time.time() * 1000))
  130. """
  131. 发送第4条指令
  132. 输入关键词
  133. """
  134. action4_dict = single_click_by_control(action4_id, control_id="com.ss.android.auto:id/jum",
  135. control_ids="com.ss.android.auto:id/s,com.ss.android.auto:id/k2k,"
  136. "com.ss.android.auto:id/p")
  137. redis_client.set(device_id + "operate", action4_id)
  138. redis_client.set(f"{device_id}_step4", "1")
  139. redis_client.delete(f"{device_id}_step3")
  140. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action4_id)
  141. return action4_dict
  142. """
  143. 点击搜索(关键词)
  144. """
  145. step4 = redis_client.get(f"{device_id}_step4")
  146. if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int(
  147. last_action_id) and perform_action_result == "success":
  148. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  149. action5_id = int(round(time.time() * 1000))
  150. """
  151. 发送第5条指令
  152. 点击搜索(关键词)
  153. """
  154. action5_dict = single_click_by_control(action5_id, control_id="com.ss.android.auto:id/jum",
  155. control_ids="com.ss.android.auto:id/s,com.ss.android.auto:id/k2k,"
  156. "com.ss.android.auto:id/p")
  157. redis_client.set(device_id + "operate", action5_id)
  158. redis_client.set(f"{device_id}_step5", "1")
  159. redis_client.delete(f"{device_id}_step4")
  160. loggerKit.info("设备:{0}, action4_id:{1}", device_id, action5_id)
  161. return action5_dict
  162. """
  163. 切换到"车友圈"tab
  164. """
  165. step5 = redis_client.get(f"{device_id}_step5")
  166. if step5 is not None and int(step5) == 1 and last_action_id is not None and int(perform_action_id) == int(
  167. last_action_id) and perform_action_result == "success":
  168. action6_id = int(round(time.time() * 1000))
  169. """
  170. 发送第5条指令
  171. 切换到"车友圈"tab
  172. """
  173. action6_dict = single_click_by_text(action6_id, text="车友圈")
  174. redis_client.set(device_id + "operate", action6_id)
  175. redis_client.set(f"{device_id}_step6", "1")
  176. redis_client.delete(f"{device_id}_step5")
  177. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action6_id)
  178. return action6_dict
  179. """
  180. 点击进圈
  181. """
  182. step6 = redis_client.get(f"{device_id}_step6")
  183. if step6 is not None and int(step6) == 1 and (
  184. last_action_id is not None and int(perform_action_id) == int(last_action_id)
  185. and perform_action_result == "success"):
  186. action7_id = int(round(time.time() * 1000))
  187. """
  188. 发送第67条指令
  189. 点击进圈
  190. """
  191. action7_dict = single_click_by_text(action7_id, text="进圈")
  192. redis_client.set(device_id + "operate", action7_id)
  193. redis_client.set(f"{device_id}_step7", "1")
  194. redis_client.delete(f"{device_id}_step6")
  195. loggerKit.info("设备:{0}, action6_id:{1}", device_id, action7_id)
  196. return action7_dict
  197. """
  198. 随机滑动3-5屏
  199. """
  200. step7 = redis_client.get(f"{device_id}_step7")
  201. if step7 is not None and int(step7) == 1 and last_action_id is not None and int(perform_action_id) == int(
  202. last_action_id) and perform_action_result == "success":
  203. action8_id = int(round(time.time() * 1000))
  204. """
  205. 发送第8条指令
  206. 随机滑动3-5屏
  207. """
  208. random_scale = random.randint(2, 6)
  209. action8_dict = swipe_screen(action8_id, scale=random_scale, timeout=30)
  210. redis_client.set(device_id + "operate", action8_id)
  211. redis_client.set(f"{device_id}_step8", "1")
  212. redis_client.delete(f"{device_id}_step7")
  213. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action8_id)
  214. return action8_dict
  215. """
  216. 点击帖子
  217. """
  218. step8 = redis_client.get(f"{device_id}_step8")
  219. if step8 is not None and int(step8) == 1 and (last_action_id is not None
  220. and int(perform_action_id) == int(last_action_id)
  221. and perform_action_result == "success"):
  222. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  223. action9_id = int(round(time.time() * 1000))
  224. """
  225. 发送第9条指令
  226. 随机滑动点击帖子
  227. """
  228. action9_dict = single_click_by_control(action9_id, control_id="com.ss.android.auto:id/jum",
  229. control_ids="com.ss.android.auto:id/s,com.ss.android.auto:id/k2k,"
  230. "com.ss.android.auto:id/p")
  231. redis_client.set(device_id + "operate", action9_id)
  232. redis_client.set(f"{device_id}_step9", "1")
  233. redis_client.delete(f"{device_id}_step8")
  234. loggerKit.info("设备:{0}, action8_id:{1}", device_id, action9_id)
  235. return action9_dict
  236. """
  237. 切换到热门帖子
  238. """
  239. step9 = redis_client.get(f"{device_id}_step9")
  240. if step9 is not None and int(step9) == 1 and (last_action_id is not None
  241. and int(perform_action_id) == int(last_action_id)
  242. and perform_action_result == "success"):
  243. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  244. action10_id = int(round(time.time() * 1000))
  245. """
  246. 发送第10条指令
  247. 随机滑动点击帖子
  248. """
  249. action10_dict = single_click_by_control(action10_id, control_id="com.ss.android.auto:id/jum",
  250. control_ids="com.ss.android.auto:id/s,com.ss.android.auto:id/k2k,"
  251. "com.ss.android.auto:id/p")
  252. redis_client.set(device_id + "operate", action10_id)
  253. redis_client.set(f"{device_id}_step10", "1")
  254. redis_client.delete(f"{device_id}_step9")
  255. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action10_id)
  256. return action10_dict
  257. """
  258. 随机滑动屏幕
  259. """
  260. step10 = redis_client.get(f"{device_id}_step10")
  261. if step10 is not None and int(step10) == 1 and last_action_id is not None and int(perform_action_id) == int(
  262. last_action_id) and perform_action_result == "success":
  263. action11_id = int(round(time.time() * 1000))
  264. """
  265. 发送第11条指令
  266. 随机滑动3-5屏
  267. """
  268. random_scale = random.randint(1, 3)
  269. action11_dict = swipe_screen(action11_id, scale=random_scale, timeout=30)
  270. redis_client.set(device_id + "operate", action11_id)
  271. redis_client.set(f"{device_id}_step11", "1")
  272. redis_client.delete(f"{device_id}_step10")
  273. loggerKit.info("设备:{0}, action10_id:{1}", device_id, action11_id)
  274. return action11_dict
  275. """
  276. 点击帖子
  277. """
  278. step11 = redis_client.get(f"{device_id}_step11")
  279. if step11 is not None and int(step11) == 1 and (last_action_id is not None
  280. and int(perform_action_id) == int(last_action_id)
  281. and perform_action_result == "success"):
  282. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  283. action12_id = int(round(time.time() * 1000))
  284. """
  285. 发送第12条指令
  286. 随机滑动点击帖子
  287. """
  288. action12_dict = single_click_by_control(action12_id, control_id="com.ss.android.auto:id/jum",
  289. control_ids="com.ss.android.auto:id/s,com.ss.android.auto:id/k2k,"
  290. "com.ss.android.auto:id/p")
  291. redis_client.set(device_id + "operate", action12_id)
  292. redis_client.set(f"{device_id}_step12", "1")
  293. redis_client.delete(f"{device_id}_step11")
  294. loggerKit.info("设备:{0}, action9_id:{1}", device_id, action12_id)
  295. return action12_dict
  296. else:
  297. action0_id = int(round(time.time() * 1000))
  298. """
  299. 启动指令
  300. 启动app
  301. """
  302. action0_dict = start_app(action0_id, target_version="7.9.0")
  303. redis_client.set(device_id + "operate", action0_id)
  304. redis_client.set(f"{device_id}_step0", "1")
  305. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  306. return action0_dict