watch_cartoon.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. """
  2. 看漫画赚金币
  3. """
  4. import time
  5. from func.action_func import del_key_vague
  6. from scene.oprator.atom_data import single_click_by_control, click_by_content, continual_swipe_screen, stop_app, \
  7. start_app
  8. from task.task_job import call_back_task_reply, callback_task
  9. from tools import redis_client, loggerKit
  10. def watch_cartoon(task_id, device_id, data):
  11. loggerKit.info('请求信息:{0}'.format(data))
  12. device_id = data.get("deviceID")
  13. perform_action_id = data.get("performActionId")
  14. result = data.get("result")
  15. inner_data = data.get("data")
  16. title = inner_data.get("resourceName")
  17. loggerKit.info("inner_data:{0}, keyword:{1}", inner_data, inner_data.get("resourceName"))
  18. if result is not None:
  19. """
  20. 非首个指令
  21. """
  22. perform_action_result = result.get("performActionResult")
  23. if perform_action_result is None:
  24. return_dict = {
  25. "data": "",
  26. "code": -2,
  27. "message": "fail, performActionResult is null"
  28. }
  29. # 回调任务中心
  30. del_key_vague(device_id)
  31. call_back_task_reply(500, '指令执行失败', task_id, device_id, 0, None, None)
  32. return return_dict
  33. # 指令执行失败
  34. if perform_action_result == "failure":
  35. # 回调任务中心
  36. return_dict = {
  37. "data": "",
  38. "code": -2,
  39. "message": "fail, performActionResult is null"
  40. }
  41. del_key_vague(device_id)
  42. call_back_task_reply(500, '指令执行失败', task_id, device_id, 0, None, None)
  43. return return_dict
  44. # 终止指令
  45. if perform_action_result == "stop":
  46. # 回调任务中心
  47. return_dict = {
  48. "data": "",
  49. "code": -2,
  50. "message": "指令被用户终止"
  51. }
  52. del_key_vague(device_id)
  53. call_back_task_reply(500, '指令被用户终止', task_id, device_id, 0, None, None)
  54. return return_dict
  55. # 终止指令
  56. if perform_action_result == "eleNotFound":
  57. # 回调任务中心
  58. return_dict = {
  59. "data": "",
  60. "code": -2,
  61. "message": "未找到签到指示"
  62. }
  63. del_key_vague(device_id)
  64. call_back_task_reply(500, '未找到签到指示,该账号当天可能已经签到过', task_id, device_id, 0, None, None)
  65. return return_dict
  66. """
  67. 每次操作完成后会将对应的操作唯一id存储到redis
  68. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  69. """
  70. last_action_id = redis_client.get(device_id + "operate")
  71. step0 = redis_client.get(f"{device_id}_step0")
  72. if (step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  73. last_action_id)
  74. and perform_action_result == "success"):
  75. action1_id = int(round(time.time() * 1000))
  76. """
  77. 发送第1条指令
  78. 点击:福利
  79. """
  80. action1_dict = single_click_by_control(action1_id, target_app="dragon",
  81. target_version="6.1.7",
  82. package_name="com.dragon.read",
  83. control_id="com.dragon.read:id/de3")
  84. redis_client.set(device_id + "operate", action1_id)
  85. redis_client.set(f"{device_id}_step1", "1")
  86. redis_client.delete(f"{device_id}_step0")
  87. loggerKit.info("taskId:{0}, action1_id:{1}", task_id, action1_id)
  88. return action1_dict
  89. step1 = redis_client.get(f"{device_id}_step1")
  90. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  91. last_action_id):
  92. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  93. action2_id = int(round(time.time() * 1000))
  94. # 元素未找到
  95. if perform_action_result == "invalid operation":
  96. # 回调任务中心
  97. return_dict = {
  98. "data": "",
  99. "code": -2,
  100. "message": "fail, performActionResult is not success"
  101. }
  102. del_key_vague(device_id)
  103. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  104. return return_dict
  105. """
  106. 发送第2条指令
  107. 向上滑动屏幕后,点击"看漫画"
  108. """
  109. action2_dict = click_by_content(action2_id,
  110. target_app="dragon",
  111. target_version="6.1.7",
  112. package_name="com.dragon.read",
  113. title="看漫画赚金币"
  114. )
  115. redis_client.set(device_id + "operate", action2_id)
  116. redis_client.set(f"{device_id}_step2", "1")
  117. redis_client.delete(f"{device_id}_step1")
  118. loggerKit.info("taskId:{0}, action2_id:{1}", task_id, action2_id)
  119. return action2_dict
  120. step2 = redis_client.get(f"{device_id}_step2")
  121. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  122. last_action_id):
  123. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  124. action3_id = int(round(time.time() * 1000))
  125. """
  126. 默认点击第一本漫画
  127. """
  128. action3_dict = single_click_by_control(action3_id,
  129. target_app="dragon",
  130. target_version="6.1.7",
  131. package_name="com.dragon.read",
  132. control_id="com.dragon.read:id/azt",
  133. control_ids="com.dragon.read:id/azt",
  134. item_index=0
  135. )
  136. redis_client.set(device_id + "operate", action3_id)
  137. redis_client.set(f"{device_id}_step3", "1")
  138. redis_client.delete(f"{device_id}_step2")
  139. loggerKit.info("taskId:{0}, action3_id:{1}", task_id, action3_id)
  140. return action3_dict
  141. step3 = redis_client.get(f"{device_id}_step3")
  142. if step3 is not None and int(step3) == 1 and last_action_id is not None and int(perform_action_id) == int(
  143. last_action_id):
  144. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  145. action4_id = int(round(time.time() * 1000))
  146. """
  147. 发送第4条指令
  148. 向下滑动若干屏幕
  149. """
  150. action4_dict = continual_swipe_screen(action4_id,
  151. target_app="dragon",
  152. target_version="6.1.7",
  153. package_name="com.dragon.read",
  154. continuous_time=2 * 60,
  155. continuous_time_interval="3,50")
  156. redis_client.set(device_id + "operate", action4_id)
  157. redis_client.set(f"{device_id}_step4", "1")
  158. redis_client.delete(f"{device_id}_step3")
  159. loggerKit.info("taskId:{0}, action4_id:{1}", task_id, action4_id)
  160. return action4_dict
  161. """
  162. 停止app
  163. """
  164. step4 = redis_client.get(f"{device_id}_step4")
  165. if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int(
  166. last_action_id) and perform_action_result == "success":
  167. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  168. action5_id = int(round(time.time() * 1000))
  169. """
  170. 停止指令
  171. 停止app
  172. """
  173. action5_dict = stop_app(action5_id, target_app="dragon",
  174. target_version="6.1.7",
  175. package_name="com.dragon.read")
  176. redis_client.delete(f"{device_id}_step4")
  177. del_key_vague(device_id)
  178. loggerKit.info("设备:{0}, action5_id:{1}", device_id, action5_dict)
  179. # 回调任务中心修改任务状态
  180. callback_task(None, None, task_id, device_id, 1, None)
  181. return action5_dict
  182. else:
  183. action0_id = int(round(time.time() * 1000))
  184. """
  185. 启动指令
  186. 启动app
  187. """
  188. action0_dict = start_app(action0_id, target_app="com.ss.android.article.lite",
  189. target_version="9.7.0.0",
  190. package_name="com.ss.android.article.lite")
  191. redis_client.set(device_id + "operate", action0_id)
  192. redis_client.set(f"{device_id}_step0", "1")
  193. redis_client.delete(f"{device_id}_step9")
  194. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  195. return action0_dict