eat_meal.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. """
  2. 吃饭补贴
  3. 领取金币
  4. """
  5. import time
  6. from func.action_func import del_key_vague
  7. from scene.oprator.atom_data import single_click_by_control, single_click_by_text, click_pic, stop_app, start_app
  8. from task.task_job import callback_task
  9. from tools import loggerKit, redis_client
  10. from tools.pic_base64_util import pic_to_base64
  11. def eat_meal(task_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. if result is not None:
  17. """
  18. 非首个指令
  19. """
  20. perform_action_result = result.get("performActionResult")
  21. if perform_action_result is None:
  22. return_dict = {
  23. "data": "",
  24. "code": -2,
  25. "message": "fail, performActionResult is null"
  26. }
  27. # 回调任务中心
  28. del_key_vague(device_id)
  29. callback_task(500, '指令执行失败', task_id, device_id, 0, None)
  30. return return_dict
  31. # 指令执行失败
  32. if perform_action_result == "failure":
  33. # 回调任务中心
  34. return_dict = {
  35. "data": "",
  36. "code": -2,
  37. "message": "fail, performActionResult is null"
  38. }
  39. del_key_vague(device_id)
  40. callback_task(500, '指令执行失败', task_id, device_id, 0, None)
  41. return return_dict
  42. # 终止指令
  43. if perform_action_result == "stop":
  44. # 回调任务中心
  45. return_dict = {
  46. "data": "",
  47. "code": -2,
  48. "message": "指令被用户终止"
  49. }
  50. del_key_vague(device_id)
  51. callback_task(500, '指令被用户终止', task_id, device_id, 0, None)
  52. return return_dict
  53. """
  54. 每次操作完成后会将对应的操作唯一id存储到redis
  55. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  56. """
  57. last_action_id = redis_client.get(device_id + "operate")
  58. step0 = redis_client.get(f"{device_id}_step0")
  59. if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  60. last_action_id) and perform_action_result == "success":
  61. action1_id = int(round(time.time() * 1000))
  62. """
  63. 发送第1条指令
  64. 首页点击任务
  65. """
  66. action1_dict = single_click_by_control(action1_id, target_app="com.ss.android.article.lite",
  67. target_version="9.7.0.0",
  68. package_name="com.ss.android.article.lite",
  69. control_id="com.ss.android.article.lite:id/kp", timeout=30)
  70. redis_client.set(device_id + "operate", action1_id)
  71. redis_client.set(f"{device_id}_{action1_id}_step1", "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. 吃饭补贴
  77. """
  78. step1 = redis_client.get(f"{device_id}_{perform_action_id}_step1")
  79. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  80. last_action_id) and perform_action_result == "success":
  81. loggerKit.info("设备:{0}, action1_id_mem:{1}", device_id, int(last_action_id))
  82. action2_id = int(round(time.time() * 1000))
  83. """
  84. 发送第2条指令
  85. 点击吃饭补贴
  86. """
  87. action2_dict = single_click_by_text(action2_id, target_app="com.ss.android.article.lite",
  88. target_version="9.7.0.0",
  89. package_name="com.ss.android.article.lite", text="吃饭补贴")
  90. redis_client.set(device_id + "operate", action2_id)
  91. redis_client.set(f"{device_id}_{action2_id}_step2", "1")
  92. redis_client.delete(f"{device_id}_{action2_id}_step1")
  93. loggerKit.info("设备:{0}, action2_id:{1}", device_id, action2_id)
  94. return action2_dict
  95. """
  96. 领取金币
  97. """
  98. step2 = redis_client.get(f"{device_id}_step2")
  99. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  100. last_action_id) and perform_action_result == "success":
  101. loggerKit.info("设备:{0}, action1_id_mem:{1}", device_id, int(last_action_id))
  102. action3_id = int(round(time.time() * 1000))
  103. """
  104. 发送第3条指令
  105. 领取金币
  106. """
  107. rectangle_base64 = pic_to_base64("pic/eat_meal.png")
  108. action3_dict = click_pic(action3_id, target_app="com.ss.android.article.lite",
  109. target_version="9.7.0.0",
  110. package_name="com.ss.android.article.lite",
  111. pic_base64=rectangle_base64)
  112. redis_client.set(device_id + "operate", action3_id)
  113. redis_client.set(f"{device_id}_step3", "1")
  114. redis_client.delete(f"{device_id}_step2")
  115. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action3_id)
  116. return action3_dict
  117. step3 = redis_client.get(f"{device_id}_step3")
  118. if step3 is not None and int(step3) == 1 and last_action_id is not None and int(perform_action_id) == int(
  119. last_action_id) and perform_action_result == "success":
  120. loggerKit.info("设备:{0}, action10_id_mem:{1}", device_id, int(last_action_id))
  121. action4_id = int(round(time.time() * 1000))
  122. """
  123. 停止指令
  124. 停止app
  125. """
  126. action4_dict = stop_app(action4_id, target_app="com.ss.android.article.lite",
  127. target_version="9.7.0.0",
  128. package_name="com.ss.android.article.lite", )
  129. del_key_vague(device_id)
  130. loggerKit.info("设备:{0}, action4_id:{1}", device_id, action4_dict)
  131. # 回调任务中心修改任务状态
  132. callback_task(None, None, task_id, device_id, 1, None)
  133. return action4_dict
  134. else:
  135. action0_id = int(round(time.time() * 1000))
  136. """
  137. 启动指令
  138. 启动app
  139. """
  140. action0_dict = start_app(action0_id, target_app="douyin", target_version="28.8.0",
  141. package_name="com.ss.android.ugc.aweme.lite")
  142. redis_client.set(device_id + "operate", action0_id)
  143. redis_client.set(f"{device_id}_step0", "1")
  144. redis_client.delete(f"{device_id}_step4")
  145. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  146. return action0_dict