random_browse.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. """
  2. 懂车帝养号
  3. 随机浏览若页面
  4. """
  5. import random
  6. import time
  7. # import numpy as np
  8. from func.action_func import del_key_vague
  9. from scene.oprator.atom_data import single_click_by_control, swipe_screen, stop_app, start_app, back_last_page
  10. from task.task_job import callback_task
  11. from tools import loggerKit, redis_client
  12. def random_browse(task_id, mobile, data):
  13. loggerKit.info('请求信息:{0}'.format(data))
  14. device_id = data.get("deviceID")
  15. perform_action_id = data.get("performActionId")
  16. result = data.get("result")
  17. if result is not None:
  18. """
  19. 非首个指令
  20. """
  21. perform_action_result = result.get("performActionResult")
  22. if perform_action_result is None:
  23. return_dict = {
  24. "data": "",
  25. "code": -2,
  26. "message": "fail, performActionResult is null"
  27. }
  28. # 回调任务中心
  29. del_key_vague(device_id)
  30. callback_task(500, '指令执行失败', task_id, mobile, 0, None)
  31. return return_dict
  32. # 指令执行失败
  33. if perform_action_result == "failure":
  34. # 回调任务中心
  35. return_dict = {
  36. "data": "",
  37. "code": -2,
  38. "message": "fail, performActionResult is null"
  39. }
  40. del_key_vague(device_id)
  41. callback_task(500, '指令执行失败', task_id, mobile, 0, None)
  42. return return_dict
  43. # 终止指令
  44. if perform_action_result == "stop":
  45. # 回调任务中心
  46. return_dict = {
  47. "data": "",
  48. "code": -2,
  49. "message": "指令被用户终止"
  50. }
  51. del_key_vague(device_id)
  52. callback_task(500, '指令被用户终止', task_id, mobile, 0, None)
  53. return return_dict
  54. """
  55. 每次操作完成后会将对应的操作唯一id存储到redis
  56. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  57. """
  58. last_action_id = redis_client.get(device_id + "operate")
  59. step0 = redis_client.get(f"{device_id}_step0")
  60. if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  61. last_action_id) and perform_action_result == "success":
  62. action1_id = int(round(time.time() * 1000))
  63. """
  64. 发送第1条指令
  65. 首页随机滑动1~6屏
  66. """
  67. # random_num = np.random.choice(range(1, 6), 6)
  68. # random_scale = random.choice(random_num)
  69. action1_dict = swipe_screen(action1_id, scale=1, timeout=30, direction='down')
  70. redis_client.set(device_id + "operate", action1_id)
  71. redis_client.set(f"{device_id}_step_start", "1")
  72. redis_client.delete(f"{device_id}_step0")
  73. loggerKit.info("设备:{0}, action1_id:{1}", device_id, action1_id)
  74. return action1_dict
  75. """
  76. 每次操作完成后会将对应的操作唯一id存储到redis
  77. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  78. """
  79. step0 = redis_client.get(f"{device_id}_step_start")
  80. if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  81. last_action_id) and perform_action_result == "success":
  82. action1_id = int(round(time.time() * 1000))
  83. """
  84. 发送第1条指令
  85. 首页随机滑动1~6屏
  86. """
  87. # random_num = np.random.choice(range(1, 6), 6)
  88. # random_scale = random.choice(random_num)
  89. random_scale = random.randint(1, 6)
  90. action1_dict = swipe_screen(action1_id, scale=random_scale, timeout=30)
  91. redis_client.set(device_id + "operate", action1_id)
  92. redis_client.set(f"{device_id}_step1", "1")
  93. redis_client.delete(f"{device_id}_step_start")
  94. loggerKit.info("设备:{0}, action1_id:{1}", device_id, action1_id)
  95. return action1_dict
  96. """
  97. 搜索关键词
  98. """
  99. step1 = redis_client.get(f"{device_id}_step1")
  100. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  101. last_action_id) and perform_action_result == "success":
  102. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  103. action2_id = int(round(time.time() * 1000))
  104. """
  105. 发送第2条指令
  106. 点击进入帖子
  107. """
  108. action2_dict = single_click_by_control(action2_id, control_id="com.ss.android.auto:id/jum",
  109. control_ids="com.ss.android.auto:id/s,com.ss.android.auto:id/k2k,"
  110. "com.ss.android.auto:id/p")
  111. redis_client.set(device_id + "operate", action2_id)
  112. redis_client.set(f"{device_id}_step2", "1")
  113. redis_client.delete(f"{device_id}_step1")
  114. loggerKit.info("设备:{0}, action2_id:{1}", device_id, action2_id)
  115. return action2_dict
  116. # stepA = redis_client.get(f"{device_id}_step2")
  117. # if stepA is not None and int(stepA) == 1 and last_action_id is not None and int(perform_action_id) == int(
  118. # last_action_id) and perform_action_result == "invalid operation":
  119. # """
  120. # 兼容千人千面
  121. # """
  122. # actionA_id = int(round(time.time() * 1000))
  123. # """
  124. # 发送第2条指令
  125. # 点击进入帖子
  126. # """
  127. # actionA_dict = single_click_by_control(actionA_id, control_id="com.ss.android.auto:id/s")
  128. #
  129. # redis_client.set(device_id + "operate", actionA_id)
  130. # redis_client.set(f"{device_id}_stepA", "1")
  131. # redis_client.delete(f"{device_id}_step2")
  132. #
  133. # loggerKit.info("设备:{0}, action2_id:{1}", device_id, actionA_id)
  134. #
  135. # return actionA_dict
  136. # stepA1 = redis_client.get(f"{device_id}_stepA")
  137. # if stepA1 is not None and int(stepA1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  138. # last_action_id) and perform_action_result == "invalid operation":
  139. # """
  140. # 兼容千人千面
  141. # """
  142. # actionA1_id = int(round(time.time() * 1000))
  143. # """
  144. # 发送第2条指令
  145. # 点击进入帖子
  146. # """
  147. # actionA1_dict = single_click_by_control(actionA1_id, control_id="com.ss.android.auto:id/k2k")
  148. #
  149. # redis_client.set(device_id + "operate", actionA1_id)
  150. # redis_client.set(f"{device_id}_stepA1", "1")
  151. # redis_client.delete(f"{device_id}_stepA")
  152. #
  153. # loggerKit.info("设备:{0}, action2_id:{1}", device_id, actionA1_id)
  154. #
  155. # return actionA1_dict
  156. # stepA2 = redis_client.get(f"{device_id}_stepA1")
  157. # if stepA2 is not None and int(stepA2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  158. # last_action_id) and perform_action_result == "invalid operation":
  159. # """
  160. # 兼容千人千面
  161. # """
  162. # actionA2_id = int(round(time.time() * 1000))
  163. # """
  164. # 发送第2条指令
  165. # 点击进入帖子
  166. # """
  167. # actionA2_dict = single_click_by_control(actionA2_id, control_id="com.ss.android.auto:id/p")
  168. #
  169. # redis_client.set(device_id + "operate", actionA2_id)
  170. # redis_client.set(f"{device_id}_stepA2", "1")
  171. # redis_client.delete(f"{device_id}_stepA1")
  172. #
  173. # loggerKit.info("设备:{0}, action2_id:{1}", device_id, actionA2_id)
  174. #
  175. # return actionA2_dict
  176. step2 = redis_client.get(f"{device_id}_step2")
  177. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  178. last_action_id) and perform_action_result == "success":
  179. action3_id = int(round(time.time() * 1000))
  180. """
  181. 发送第3条指令
  182. 在帖子中随机滑动1~3屏
  183. """
  184. # random_num = np.random.choice(range(1, 3), 3)
  185. # random_scale = random.choice(random_num)
  186. random_scale = random.randint(1, 3)
  187. action3_dict = swipe_screen(action3_id, scale=random_scale, timeout=30)
  188. redis_client.set(device_id + "operate", action3_id)
  189. redis_client.set(f"{device_id}_step3", "1")
  190. redis_client.delete(f"{device_id}_step2")
  191. # redis_client.delete(f"{device_id}_stepA")
  192. # redis_client.delete(f"{device_id}_stepA1")
  193. # redis_client.delete(f"{device_id}_stepA2")
  194. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action3_id)
  195. return action3_dict
  196. step3 = redis_client.get(f"{device_id}_step3")
  197. if step3 is not None and int(step3) == 1 and (
  198. last_action_id is not None and int(perform_action_id) == int(last_action_id)
  199. and perform_action_result == "success"):
  200. action4_id = int(round(time.time() * 1000))
  201. """
  202. 发送第4条指令
  203. 退出当前帖子
  204. """
  205. action1_dict = back_last_page(action4_id)
  206. redis_client.set(device_id + "operate", action4_id)
  207. redis_client.set(f"{device_id}_step4", "1")
  208. redis_client.delete(f"{device_id}_step3")
  209. loggerKit.info("设备:{0}, action4_id:{1}", device_id, action4_id)
  210. return action1_dict
  211. step4 = redis_client.get(f"{device_id}_step4")
  212. if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int(
  213. last_action_id) and perform_action_result == "success":
  214. action5_id = int(round(time.time() * 1000))
  215. """
  216. 发送第5条指令
  217. 首页随机滑动1~6屏
  218. """
  219. # random_num = np.random.choice(range(1, 6), 6)
  220. # random_scale = random.choice(random_num)
  221. random_scale = random.randint(1, 6)
  222. action1_dict = swipe_screen(action5_id, scale=random_scale, timeout=30)
  223. redis_client.set(device_id + "operate", action5_id)
  224. redis_client.set(f"{device_id}_step5", "1")
  225. redis_client.delete(f"{device_id}_step4")
  226. loggerKit.info("设备:{0}, action5_id:{1}", device_id, action5_id)
  227. return action1_dict
  228. step5 = redis_client.get(f"{device_id}_step5")
  229. if step5 is not None and int(step5) == 1 and (last_action_id is not None
  230. and int(perform_action_id) == int(last_action_id)
  231. and perform_action_result == "success"):
  232. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  233. action6_id = int(round(time.time() * 1000))
  234. """
  235. 发送第6条指令
  236. 点击进入帖子
  237. """
  238. action2_dict = single_click_by_control(action6_id, control_id="com.ss.android.auto:id/jum",
  239. control_ids="com.ss.android.auto:id/s,com.ss.android.auto:id/k2k,"
  240. "com.ss.android.auto:id/p")
  241. redis_client.set(device_id + "operate", action6_id)
  242. redis_client.set(f"{device_id}_step6", "1")
  243. redis_client.delete(f"{device_id}_step5")
  244. loggerKit.info("设备:{0}, action6_id:{1}", device_id, action6_id)
  245. return action2_dict
  246. # stepB = redis_client.get(f"{device_id}_step6")
  247. # if stepB is not None and int(stepB) == 1 and last_action_id is not None and int(perform_action_id) == int(
  248. # last_action_id) and perform_action_result == "invalid operation":
  249. # """
  250. # 兼容千人千面
  251. # """
  252. # actionB_id = int(round(time.time() * 1000))
  253. # """
  254. # 发送第2条指令
  255. # 点击进入帖子
  256. # """
  257. # actionB_dict = single_click_by_control(actionB_id, control_id="com.ss.android.auto:id/s")
  258. #
  259. # redis_client.set(device_id + "operate", actionB_id)
  260. # redis_client.set(f"{device_id}_stepB", "1")
  261. # redis_client.delete(f"{device_id}_step6")
  262. #
  263. # loggerKit.info("设备:{0}, action6_id:{1}", device_id, actionB_id)
  264. #
  265. # return actionB_dict
  266. # stepB1 = redis_client.get(f"{device_id}_stepB")
  267. # if stepB1 is not None and int(stepB1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  268. # last_action_id) and perform_action_result == "invalid operation":
  269. # """
  270. # 兼容千人千面
  271. # """
  272. # actionB1_id = int(round(time.time() * 1000))
  273. # """
  274. # 发送第2条指令
  275. # 点击进入帖子
  276. # """
  277. # actionB1_dict = single_click_by_control(actionB1_id, control_id="com.ss.android.auto:id/k2k")
  278. #
  279. # redis_client.set(device_id + "operate", actionB1_id)
  280. # redis_client.set(f"{device_id}_stepB1", "1")
  281. # redis_client.delete(f"{device_id}_stepB")
  282. #
  283. # loggerKit.info("设备:{0}, action6_id:{1}", device_id, actionB1_id)
  284. #
  285. # return actionB1_dict
  286. # stepB2 = redis_client.get(f"{device_id}_stepB1")
  287. # if stepB2 is not None and int(stepB2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  288. # last_action_id) and perform_action_result == "invalid operation":
  289. # """
  290. # 兼容千人千面
  291. # """
  292. # actionB2_id = int(round(time.time() * 1000))
  293. # """
  294. # 发送第2条指令
  295. # 点击进入帖子
  296. # """
  297. # actionB2_dict = single_click_by_control(actionB2_id, control_id="com.ss.android.auto:id/p")
  298. #
  299. # redis_client.set(device_id + "operate", actionB2_id)
  300. # redis_client.set(f"{device_id}_stepB2", "1")
  301. # redis_client.delete(f"{device_id}_stepB1")
  302. #
  303. # loggerKit.info("设备:{0}, action6_id:{1}", device_id, actionB2_id)
  304. #
  305. # return actionB2_dict
  306. step6 = redis_client.get(f"{device_id}_step6")
  307. if (step6 is not None and int(step6) == 1 and last_action_id is not None and int(perform_action_id) == int(
  308. last_action_id)
  309. and perform_action_result == "success"):
  310. action7_id = int(round(time.time() * 1000))
  311. """
  312. 发送第7条指令
  313. 在帖子中随机滑动1~3屏
  314. """
  315. # random_num = np.random.choice(range(1, 3), 6)
  316. # random_scale = random.choice(random_num)
  317. random_scale = random.randint(1, 3)
  318. action1_dict = swipe_screen(action7_id, scale=random_scale, timeout=30)
  319. redis_client.set(device_id + "operate", action7_id)
  320. redis_client.set(f"{device_id}_step7", "1")
  321. redis_client.delete(f"{device_id}_step6")
  322. # redis_client.delete(f"{device_id}_stepB")
  323. # redis_client.delete(f"{device_id}_stepB1")
  324. # redis_client.delete(f"{device_id}_stepB2")
  325. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action7_id)
  326. return action1_dict
  327. step7 = redis_client.get(f"{device_id}_step7")
  328. if (step7 is not None and int(step7) == 1 and last_action_id is not None
  329. and int(perform_action_id) == int(last_action_id) and perform_action_result == "success"):
  330. action8_id = int(round(time.time() * 1000))
  331. """
  332. 发送第8条指令
  333. 退出当前帖子
  334. """
  335. action8_dict = back_last_page(action8_id)
  336. redis_client.set(device_id + "operate", action8_id)
  337. redis_client.set(f"{device_id}_step8", "1")
  338. redis_client.delete(f"{device_id}_step7")
  339. loggerKit.info("设备:{0}, action8_id:{1}", device_id, action8_id)
  340. return action8_dict
  341. step8 = redis_client.get(f"{device_id}_step8")
  342. if step8 is not None and int(step8) == 1 and (last_action_id is not None
  343. and int(perform_action_id) == int(last_action_id)
  344. and perform_action_result == "success"):
  345. loggerKit.info("设备:{0}, action8_id_mem:{1}", device_id, int(last_action_id))
  346. action9_id = int(round(time.time() * 1000))
  347. """
  348. 发送第9条指令
  349. 关闭app
  350. """
  351. action9_dict = stop_app(action9_id, target_version="7.9.0")
  352. del_key_vague(device_id)
  353. loggerKit.info("设备:{0}, action9_id:{1}", device_id, action9_dict)
  354. # 回调任务中心修改任务状态
  355. callback_task(None, None, task_id, mobile, 1, None)
  356. return action9_dict
  357. else:
  358. action0_id = int(round(time.time() * 1000))
  359. """
  360. 启动指令
  361. 启动app
  362. """
  363. action0_dict = start_app(action0_id, target_version="7.9.0")
  364. redis_client.set(device_id + "operate", action0_id)
  365. redis_client.set(f"{device_id}_step0", "1")
  366. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  367. return action0_dict