watch_video.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. """
  2. 完整刷普通视频
  3. """
  4. import base64
  5. import time
  6. from func.action_func import del_key_vague
  7. from scene.oprator.atom_data import single_click_by_control, click_pic, continual_swipe_screen, stop_app, start_app
  8. from task.task_job import callback_task
  9. from tools import loggerKit, redis_client
  10. """
  11. 头条极速版
  12. 刷视频
  13. """
  14. def watch_video(task_id, data):
  15. loggerKit.info("[头条极速版]请求信息:{0}'.format(data))")
  16. device_id = data.get("deviceID")
  17. perform_action_id = data.get("performActionId")
  18. result = data.get("result")
  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. 每次操作完成后会将对应的操作唯一id存储到redis
  58. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  59. """
  60. last_action_id = redis_client.get(device_id + "operate")
  61. step0 = redis_client.get(f"{device_id}_step0")
  62. if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  63. last_action_id) and perform_action_result == "success":
  64. action1_id = int(round(time.time() * 1000))
  65. """
  66. 发送第1条指令
  67. 首页点击任务
  68. """
  69. action1_dict = single_click_by_control(action1_id, target_app="com.ss.android.article.lite",
  70. target_version="9.7.0.0",
  71. package_name="com.ss.android.article.lite",
  72. control_id="com.ss.android.article.lite:id/kp", timeout=30)
  73. redis_client.set(device_id + "operate", action1_id)
  74. redis_client.set(f"{device_id}_{action1_id}_step1", "1")
  75. redis_client.delete(f"{device_id}_step0")
  76. loggerKit.info("设备:{0}, action1_id:{1}", device_id, action1_id)
  77. return action1_dict
  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. with open("pic/single_video.png", "rb") as image_file:
  88. encoded_string = base64.b64encode(image_file.read())
  89. action2_dict = click_pic(action2_id, target_app="com.ss.android.article.lite", target_version="9.7.0.0",
  90. package_name="com.ss.android.article.lite", pic_base64=encoded_string)
  91. redis_client.set(device_id + "operate", action2_id)
  92. redis_client.set(f"{device_id}_{action2_id}_step2", "1")
  93. redis_client.delete(f"{device_id}_{action2_id}_step1")
  94. loggerKit.info("设备:{0}, action2_id:{1}", device_id, action2_id)
  95. return action2_dict
  96. step2 = redis_client.get(f"{device_id}_{perform_action_id}_step2")
  97. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  98. last_action_id) and perform_action_result == "success":
  99. loggerKit.info("设备:{0}, action2_id_mem:{1}", device_id, int(last_action_id))
  100. action3_id = int(round(time.time() * 1000))
  101. """
  102. 发送第3条指令
  103. 持续滑动屏幕
  104. """
  105. action3_dict = continual_swipe_screen(action3_id, target_app="com.ss.android.article.lite",
  106. target_version="9.7.0.0",
  107. package_name="com.ss.android.article.lite", continuous_time=180 * 5)
  108. redis_client.set(device_id + "operate", action3_id)
  109. redis_client.set(f"{device_id}_{action3_id}_step3", "1")
  110. redis_client.delete(f"{device_id}_{action3_id}_step2")
  111. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action3_id)
  112. return action3_dict
  113. """
  114. 停止app
  115. """
  116. step4 = redis_client.get(f"{device_id}_step4")
  117. if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int(
  118. last_action_id) and perform_action_result == "success":
  119. loggerKit.info("设备:{0}, action10_id_mem:{1}", device_id, int(last_action_id))
  120. action5_id = int(round(time.time() * 1000))
  121. """
  122. 停止指令
  123. 停止app
  124. """
  125. action5_dict = stop_app(action5_id, target_app="com.ss.android.article.lite",
  126. target_version="9.7.0.0",
  127. package_name="com.ss.android.article.lite")
  128. redis_client.delete(f"{device_id}_step4")
  129. del_key_vague(device_id)
  130. loggerKit.info("设备:{0}, action12_id:{1}", device_id, action5_dict)
  131. # 回调任务中心修改任务状态
  132. callback_task(None, None, task_id, device_id, 1, None)
  133. return action5_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="com.ss.android.article.lite",
  141. target_version="9.7.0.0",
  142. package_name="com.ss.android.article.lite")
  143. redis_client.set(device_id + "operate", action0_id)
  144. redis_client.set(f"{device_id}_step0", "1")
  145. redis_client.delete(f"{device_id}_step9")
  146. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  147. return action0_dict