douyin_live_comment.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. # 抖音直播间评论脚本
  2. import random
  3. import time
  4. from func.action_func import del_key_vague
  5. from task.task_job import callback_task
  6. from tools import loggerKit, redis_client
  7. from scene.oprator.atom_data import start_app, stop_app, get_text_by_control, single_click_by_control, \
  8. send_text_by_control, many_click_by_position, single_click_by_text
  9. import yaml
  10. import json
  11. import httpx
  12. with open('config.yaml', 'r') as file:
  13. config = yaml.load(file, Loader=yaml.FullLoader)
  14. extern_domain = config['bmp-cp']['extern_domain']
  15. # 任务执行回调url
  16. task_callback_url = extern_domain + config['bmp-cp']['task_callback_url']
  17. # 调用AIGC接口
  18. post_ai_gc_url = extern_domain + config['bmp-content-center']['comment_local_url']
  19. # 抖音互动 (根据视频链接 进行搜索获取到对应的视频进行点赞 收藏 评论)
  20. # version 29.5.0
  21. def douyin_spider(task_id, keyword, data):
  22. loggerKit.info('请求信息:{0}'.format(data))
  23. device_id = data.get("deviceID")
  24. perform_action_id = data.get("performActionId")
  25. result = data.get("result")
  26. extension_info = data['data']['extendInfo']
  27. extension_info = json.loads(extension_info)
  28. keyword = extension_info['liveURL']
  29. if result is not None:
  30. """
  31. 非首个指令
  32. """
  33. perform_action_result = result.get("performActionResult")
  34. if perform_action_result is None:
  35. return_dict = {
  36. "data": "",
  37. "code": -2,
  38. "message": "fail, performActionResult is null"
  39. }
  40. # 回调任务中心
  41. del_key_vague(device_id)
  42. callback_task(500, '指令执行失败', task_id, device_id, 0, None)
  43. return return_dict
  44. if perform_action_result == "failure":
  45. # 回调任务中心
  46. return_dict = {
  47. "data": "",
  48. "code": -2,
  49. "message": "fail, performActionResult is not success"
  50. }
  51. del_key_vague(device_id)
  52. callback_task(500, '任务执行失败,可能当前无法再次执行看广告任务', task_id, device_id, 0, None)
  53. return return_dict
  54. if perform_action_result == "stop":
  55. # 回调任务中心
  56. return_dict = {
  57. "data": "",
  58. "code": -2,
  59. "message": "fail, performActionResult is not success"
  60. }
  61. del_key_vague(device_id)
  62. callback_task(500, '指令被用户终止', task_id, device_id, 0, None)
  63. return return_dict
  64. # 每次操作完成后会将对应的操作唯一id存储到redis,并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  65. last_action_id = redis_client.get(device_id + "operate")
  66. step0 = redis_client.get(f"{device_id}_step0")
  67. if (step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  68. last_action_id)
  69. and perform_action_result == "success"):
  70. action1_id = int(round(time.time() * 1000))
  71. """
  72. 发送第1条指令
  73. 点击:我(菜单)
  74. """
  75. action1_dict = single_click_by_text(action1_id, target_app="douyin", target_version="28.8.0",
  76. package_name="com.ss.android.ugc.aweme.lite",
  77. text="我")
  78. redis_client.set(device_id + "operate", action1_id)
  79. redis_client.set(f"{device_id}_step_me", "1")
  80. redis_client.delete(f"{device_id}_step0")
  81. loggerKit.info("taskId:{0}, action1_id:{1}", task_id, action1_id)
  82. return action1_dict
  83. # 获取到对应抖音账号并存入redis:
  84. step1 = redis_client.get(f"{device_id}_step_me")
  85. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  86. last_action_id):
  87. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  88. action2_id = int(round(time.time() * 1000))
  89. """
  90. 插播指令 获取当前的抖音账号
  91. 获取当前抖音账号
  92. """
  93. action2_dict = get_text_by_control(action2_id,
  94. control_id="com.ss.android.ugc.aweme.lite:id/ib7",
  95. target_app="douyin",
  96. target_version="28.8.0",
  97. package_name="com.ss.android.ugc.aweme.lite",
  98. sleep_time=3)
  99. redis_client.set(device_id + "operate", action2_id)
  100. redis_client.set(f"{device_id}_step_get_account", "1")
  101. redis_client.delete(f"{device_id}_step_me")
  102. loggerKit.info("taskId:{0}, action2_id:{1}", task_id, action2_id)
  103. return action2_dict
  104. step1 = redis_client.get(f"{device_id}_step_get_account")
  105. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  106. last_action_id):
  107. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  108. action2_id = int(round(time.time() * 1000))
  109. # 获取当前登陆账号并存入缓存
  110. account_name = result.get("performActionText")
  111. if account_name is None:
  112. # 回调任务中心
  113. return_dict = {
  114. "data": "",
  115. "code": -2,
  116. "message": "未获取到账号信息"
  117. }
  118. del_key_vague(device_id)
  119. callback_task(500, '未获取到账号信息', task_id, device_id, 0, None)
  120. return return_dict
  121. # 将当前设备操作的账号存入redis
  122. redis_client.set(device_id + 'account', account_name)
  123. """
  124. 发送第2条指令
  125. 点击:首页
  126. """
  127. action2_dict = single_click_by_text(action2_id, target_app="douyin", target_version="28.8.0",
  128. package_name="com.ss.android.ugc.aweme.lite",
  129. text="首页")
  130. redis_client.set(device_id + "operate", action2_id)
  131. redis_client.set(f"{device_id}_step_search", "1")
  132. redis_client.delete(f"{device_id}_step_get_account")
  133. loggerKit.info("taskId:{0}, action2_id:{1}", task_id, action2_id)
  134. return action2_dict
  135. step0 = redis_client.get(f"{device_id}_step_search")
  136. if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  137. last_action_id):
  138. # 元素未找到
  139. if perform_action_result == "invalid operation":
  140. # 回调任务中心
  141. return_dict = {
  142. "data": "",
  143. "code": -2,
  144. "message": "fail, performActionResult is null"
  145. }
  146. del_key_vague(device_id)
  147. callback_task(500, '回到首页失败', task_id, device_id, 0, None)
  148. return return_dict
  149. action1_id = int(round(time.time() * 1000))
  150. """
  151. 发送第1条指令
  152. 点击搜索框
  153. """
  154. action1_dict = single_click_by_control(action1_id, target_app="douyin", target_version="28.8.0",
  155. package_name="com.ss.android.ugc.aweme.lite",
  156. control_id="com.ss.android.ugc.aweme.lite:id/dxw", timeout=5)
  157. redis_client.set(device_id + "operate", action1_id)
  158. redis_client.set(f"{device_id}_step1", "1")
  159. redis_client.delete(f"{device_id}_step_search")
  160. loggerKit.info("设备:{0}, action1_id:{1}", device_id, action1_id)
  161. return action1_dict
  162. step1 = redis_client.get(f"{device_id}_step1")
  163. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  164. last_action_id) and perform_action_result == "success":
  165. loggerKit.info("设备:{0}, action2_id_mem:{1}", device_id, int(last_action_id))
  166. # 元素未找到
  167. if perform_action_result == "invalid operation":
  168. # 回调任务中心
  169. return_dict = {
  170. "data": "",
  171. "code": -2,
  172. "message": "fail, performActionResult is null"
  173. }
  174. del_key_vague(device_id)
  175. callback_task(500, '点击搜索按钮失败', task_id, device_id, 0, None)
  176. return return_dict
  177. action2_id = int(round(time.time() * 1000))
  178. """
  179. 发送第2条指令
  180. 对搜索框进行赋值
  181. """
  182. action2_dict = send_text_by_control(action2_id, target_app="douyin", target_version="28.8.0",
  183. package_name="com.ss.android.ugc.aweme.lite",
  184. control_id="com.ss.android.ugc.aweme.lite:id/et_search_kw",
  185. content=keyword, timeout=5)
  186. redis_client.set(device_id + "operate", action2_id)
  187. redis_client.set(f"{device_id}_step2", "1")
  188. redis_client.delete(f"{device_id}_step1")
  189. loggerKit.info("设备:{0}, action2_id:{1}", device_id, action2_id)
  190. return action2_dict
  191. step2 = redis_client.get(f"{device_id}_step2")
  192. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  193. last_action_id) and perform_action_result == "success":
  194. loggerKit.info("设备:{0}, action3_id_mem:{1}", device_id, int(last_action_id))
  195. # 元素未找到
  196. if perform_action_result == "invalid operation":
  197. # 回调任务中心
  198. return_dict = {
  199. "data": "",
  200. "code": -2,
  201. "message": "fail, performActionResult is null"
  202. }
  203. del_key_vague(device_id)
  204. callback_task(500, '搜索框赋值失败', task_id, device_id, 0, None)
  205. return return_dict
  206. action3_id = int(round(time.time() * 1000))
  207. """
  208. 发送第3条指令
  209. 点击搜索按钮
  210. """
  211. comment_count = random.randint(5, 8)
  212. redis_client.set(device_id + 'comment_count', comment_count)
  213. loggerKit.info("任务id:{0}, 评论次数:{1}", task_id, comment_count)
  214. action3_dict = single_click_by_control(action3_id, target_app="douyin", target_version="28.8.0",
  215. package_name="com.ss.android.ugc.aweme.lite",
  216. control_id="com.ss.android.ugc.aweme.lite:id/nou")
  217. redis_client.set(device_id + "operate", action3_id)
  218. redis_client.set(f"{device_id}_step3", "1")
  219. redis_client.delete(f"{device_id}_step2")
  220. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action3_id)
  221. return action3_dict
  222. # 第四步 判断是否可分享 不可分享开始评论
  223. step3 = redis_client.get(f"{device_id}_step3")
  224. if step3 is not None and int(step3) == 1 and last_action_id is not None and int(perform_action_id) == int(
  225. last_action_id) and perform_action_result == "success":
  226. loggerKit.info("设备:{0}, action3_id_mem:{1}", device_id, int(last_action_id))
  227. # 元素未找到
  228. if perform_action_result == "invalid operation":
  229. # 回调任务中心
  230. return_dict = {
  231. "data": "",
  232. "code": -2,
  233. "message": "fail, performActionResult is null"
  234. }
  235. del_key_vague(device_id)
  236. callback_task(500, '搜索框赋值失败', task_id, device_id, 0, None)
  237. return return_dict
  238. action4_id = int(round(time.time() * 1000))
  239. account_name = redis_client.get(device_id + 'account')
  240. # 判断该设备是否对该链接进行过转发
  241. done_link = redis_client.set_nx(account_name + keyword, 'done')
  242. if done_link:
  243. """
  244. 发送第4条指令
  245. 点击更多 开始分享
  246. """
  247. action6_dict = single_click_by_control(action4_id, target_app="douyin", target_version="28.8.0",
  248. package_name="com.ss.android.ugc.aweme.lite",
  249. control_id="m.l.live.plugin:id/more_toolbar_icon", timeout=5)
  250. redis_client.set(device_id + "operate", action4_id)
  251. redis_client.set(f"{device_id}_step4", "1")
  252. redis_client.delete(f"{device_id}_step3")
  253. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action4_id)
  254. return action6_dict
  255. """
  256. 发送第4条指令
  257. 点开直播间对应的输入框
  258. """
  259. action6_dict = many_click_by_position(action4_id, target_app="douyin", target_version="28.8.0",
  260. package_name="com.ss.android.ugc.aweme.lite",
  261. count=2, timeout=5)
  262. redis_client.set(device_id + "operate", action4_id)
  263. redis_client.set(f"{device_id}_step6", "1")
  264. redis_client.delete(f"{device_id}_step3")
  265. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action4_id)
  266. return action6_dict
  267. # 第5步
  268. # 点击分享
  269. step4 = redis_client.get(f"{device_id}_step4")
  270. if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int(
  271. last_action_id) \
  272. and perform_action_result == "success":
  273. loggerKit.info("设备:{0}, action6_id_mem:{1}", device_id, int(last_action_id))
  274. # 元素未找到
  275. if perform_action_result == "invalid operation":
  276. # 回调任务中心
  277. return_dict = {
  278. "data": "",
  279. "code": -2,
  280. "message": "fail, performActionResult is null"
  281. }
  282. del_key_vague(device_id)
  283. callback_task(500, '点击直播间右下角更多按钮失败', task_id, device_id, 0, None)
  284. return return_dict
  285. action5_id = int(round(time.time() * 1000))
  286. """
  287. 发送第5条指令
  288. 点击分享
  289. """
  290. action6_dict = single_click_by_text(action5_id, target_app="douyin", target_version="28.8.0",
  291. package_name="com.ss.android.ugc.aweme.lite",
  292. text="分享", timeout=5)
  293. redis_client.set(device_id + "operate", action5_id)
  294. redis_client.set(f"{device_id}_step5", "1")
  295. redis_client.delete(f"{device_id}_step4")
  296. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action5_id)
  297. return action6_dict
  298. # 第6步
  299. # 点击复制链接
  300. step4 = redis_client.get(f"{device_id}_step5")
  301. if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int(
  302. last_action_id) \
  303. and perform_action_result == "success":
  304. loggerKit.info("设备:{0}, action6_id_mem:{1}", device_id, int(last_action_id))
  305. # 元素未找到
  306. if perform_action_result == "invalid operation":
  307. # 回调任务中心
  308. return_dict = {
  309. "data": "",
  310. "code": -2,
  311. "message": "fail, performActionResult is null"
  312. }
  313. del_key_vague(device_id)
  314. callback_task(500, '点击分享失败', task_id, device_id, 0, None)
  315. return return_dict
  316. action5_id = int(round(time.time() * 1000))
  317. """
  318. 发送第5条指令
  319. 点击分享
  320. """
  321. action6_dict = single_click_by_text(action5_id, target_app="douyin", target_version="28.8.0",
  322. package_name="com.ss.android.ugc.aweme.lite",
  323. text="复制链接", timeout=5)
  324. redis_client.set(device_id + "operate", action5_id)
  325. redis_client.set(f"{device_id}_step6", "1")
  326. redis_client.delete(f"{device_id}_step5")
  327. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action5_id)
  328. return action6_dict
  329. # 第7步
  330. # 点击
  331. step6 = redis_client.get(f"{device_id}_step6")
  332. if step6 is not None and int(step6) == 1 and last_action_id is not None and int(perform_action_id) == int(
  333. last_action_id) \
  334. and perform_action_result == "success":
  335. loggerKit.info("设备:{0}, action6_id_mem:{1}", device_id, int(last_action_id))
  336. # 元素未找到
  337. if perform_action_result == "invalid operation":
  338. # 回调任务中心
  339. return_dict = {
  340. "data": "",
  341. "code": -2,
  342. "message": "fail, performActionResult is null"
  343. }
  344. del_key_vague(device_id)
  345. callback_task(500, '点击搜索按钮/分享链接失败', task_id, device_id, 0, None)
  346. return return_dict
  347. action6_id = int(round(time.time() * 1000))
  348. """
  349. 发送第7条指令
  350. 点开直播间对应的输入框
  351. """
  352. action6_dict = single_click_by_control(action6_id, target_app="douyin", target_version="28.8.0",
  353. package_name="com.ss.android.ugc.aweme.lite",
  354. control_id="m.l.live.plugin:id/edit_btn_audience", timeout=5)
  355. redis_client.set(device_id + "operate", action6_id)
  356. redis_client.set(f"{device_id}_step8", "1")
  357. redis_client.delete(f"{device_id}_step6")
  358. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action6_id)
  359. return action6_dict
  360. step8 = redis_client.get(f"{device_id}_step8")
  361. if step8 is not None and int(step8) == 1 and last_action_id is not None and int(perform_action_id) == int(
  362. last_action_id) \
  363. and perform_action_result == "success":
  364. loggerKit.info("设备:{0}, action6_id_mem:{1}", device_id, int(last_action_id))
  365. # 元素未找到
  366. if perform_action_result == "invalid operation":
  367. # 回调任务中心
  368. return_dict = {
  369. "data": "",
  370. "code": -2,
  371. "message": "fail, performActionResult is null"
  372. }
  373. del_key_vague(device_id)
  374. callback_task(500, '唤醒评论输入框失败', task_id, device_id, 0, None)
  375. return return_dict
  376. action9_id = int(round(time.time() * 1000))
  377. """
  378. 发送第9条指令
  379. 根据视频内容 生成评论文案将文案缓存 并且点击评论
  380. 如果没获取到对应的评论 任务结束 关闭
  381. """
  382. request_data = {
  383. "title": "",
  384. "comment": "",
  385. "platform": "douyin",
  386. "mode": "1"
  387. }
  388. loggerKit.info("任务id:{0},请求AIGC信息:{1}", task_id, request_data)
  389. response = httpx.post(post_ai_gc_url, json=request_data, timeout=120)
  390. if not response.is_success:
  391. # 调用AIGC获取评论失败
  392. loggerKit.info("任务id:{0}对应标题:{1},请求AIGC失败信息:{2},返回信息:{3}", task_id, keyword, request_data, response)
  393. reply = '不错👍'
  394. response_body = json.loads(response.text)
  395. reply_data = response_body.get('data')
  396. reply = reply_data.get('comment')
  397. if '内容太少' in reply or '对不起' in reply or reply is None or reply == '' or '提供' in reply:
  398. # 获取到的评论内容不符合
  399. loggerKit.info("任务id:{0}对应标题:{1},请求AIGC失败信息:{2},返回信息:{3}", task_id, keyword, request_data, response)
  400. reply = '不错👍'
  401. redis_client.set(device_id + "operate", action9_id)
  402. redis_client.set(f"{device_id}_step9", "1")
  403. redis_client.delete(f"{device_id}_step8")
  404. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action9_id)
  405. # 评论框赋值
  406. action9_dict = send_text_by_control(action9_id, target_app="douyin", target_version="28.8.0",
  407. package_name="com.ss.android.ugc.aweme.lite",
  408. control_id="m.l.live.plugin:id/edit_text_container",
  409. content=reply, timeout=5, sleep_time=5, item_index=0)
  410. return action9_dict
  411. step9 = redis_client.get(f"{device_id}_step9")
  412. if step9 is not None and int(step9) == 1 and last_action_id is not None and int(perform_action_id) == int(
  413. last_action_id) \
  414. and perform_action_result == "success":
  415. loggerKit.info("设备:{0}, action9_id_mem:{1}", device_id, int(last_action_id))
  416. # 元素未找到
  417. if perform_action_result == "invalid operation":
  418. # 回调任务中心
  419. return_dict = {
  420. "data": "",
  421. "code": -2,
  422. "message": "fail, performActionResult is null"
  423. }
  424. del_key_vague(device_id)
  425. callback_task(500, '评论输入框赋值失败', task_id, device_id, 0, None)
  426. return return_dict
  427. action10_id = int(round(time.time() * 1000))
  428. """
  429. 发送第10条指令
  430. 发送评论
  431. """
  432. action10_dict = single_click_by_control(action10_id, target_app="douyin", target_version="28.8.0",
  433. package_name="com.ss.android.ugc.aweme.lite",
  434. control_id="m.l.live.plugin:id/input_panel_send_view", timeout=5,
  435. sleep_time=5)
  436. redis_client.set(device_id + "operate", action10_id)
  437. redis_client.set(f"{device_id}_step10", "1")
  438. redis_client.delete(f"{device_id}_step9")
  439. loggerKit.info("设备:{0}, action10_id:{1}", device_id, action10_id)
  440. return action10_dict
  441. step10 = redis_client.get(f"{device_id}_step10")
  442. if step10 is not None and int(step10) == 1 and last_action_id is not None and int(perform_action_id) == int(
  443. last_action_id) \
  444. and perform_action_result == "success":
  445. loggerKit.info("设备:{0}, action10_id_mem:{1}", device_id, int(last_action_id))
  446. # 元素未找到
  447. if perform_action_result == "invalid operation":
  448. # 回调任务中心
  449. return_dict = {
  450. "data": "",
  451. "code": -2,
  452. "message": "fail, performActionResult is null"
  453. }
  454. del_key_vague(device_id)
  455. callback_task(500, '发送评论失败', task_id, device_id, 0, None)
  456. return return_dict
  457. action11_id = int(round(time.time() * 1000))
  458. """
  459. 发送第11条指令
  460. 点赞直播间
  461. """
  462. like_count = random.randint(10, 15)
  463. action11_dict = many_click_by_position(action11_id, target_app="douyin", target_version="28.8.0",
  464. package_name="com.ss.android.ugc.aweme.lite",
  465. count=like_count, timeout=5)
  466. redis_client.set(device_id + "operate", action11_id)
  467. redis_client.set(f"{device_id}_step11", "1")
  468. redis_client.delete(f"{device_id}_step10")
  469. loggerKit.info("设备:{0}, action10_id:{1}", device_id, action11_id)
  470. return action11_dict
  471. """
  472. 停止app
  473. """
  474. step10 = redis_client.get(f"{device_id}_step11")
  475. if step10 is not None and int(step10) == 1 and last_action_id is not None and int(perform_action_id) == int(
  476. last_action_id):
  477. loggerKit.info("设备:{0}, action10_id_mem:{1}", device_id, int(last_action_id))
  478. # 已完成任务数
  479. done_comment_count = redis_client.incr(device_id + "done_count", 1)
  480. # 预期完成任务数
  481. anticipate_comment_count = redis_client.get(device_id + 'comment_count')
  482. action12_id = int(round(time.time() * 1000))
  483. # 如果已经达到预期评论次数 结束任务
  484. if int(done_comment_count) >= int(anticipate_comment_count):
  485. """
  486. 停止指令
  487. 停止app
  488. """
  489. action12_dict = stop_app(action12_id, target_app="douyin", target_version="28.8.0",
  490. package_name="com.ss.android.ugc.aweme.lite", timeout=5)
  491. del_key_vague(device_id)
  492. loggerKit.info("设备:{0}, action11_id:{1}", device_id, action12_id)
  493. # 回调任务中心修改任务状态
  494. callback_task(None, None, task_id, device_id, 1, None)
  495. return action12_dict
  496. # 未达到评论次数 重新开始评论
  497. """
  498. 发送第7条指令
  499. 点开直播间对应的输入框
  500. """
  501. action6_dict = single_click_by_control(action12_id, target_app="douyin", target_version="28.8.0",
  502. package_name="com.ss.android.ugc.aweme.lite",
  503. control_id="m.l.live.plugin:id/edit_btn_audience", timeout=5)
  504. redis_client.set(device_id + "operate", action12_id)
  505. redis_client.set(f"{device_id}_step8", "1")
  506. redis_client.delete(f"{device_id}_step11")
  507. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action12_id)
  508. return action6_dict
  509. else:
  510. action0_id = int(round(time.time() * 1000))
  511. """
  512. 启动指令
  513. 启动app
  514. """
  515. action0_dict = start_app(action0_id, target_app="douyin", target_version="29.5.0",
  516. package_name="com.ss.android.ugc.aweme.lite")
  517. redis_client.set(device_id + "operate", action0_id)
  518. redis_client.set(f"{device_id}_step0", "1")
  519. redis_client.delete(f"{device_id}_step9")
  520. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  521. return action0_dict
  522. # 批量模糊删除缓存
  523. # def del_key_vague(device_id):
  524. # # 批量模糊删除keys
  525. # keys = redis_client.match_pattern_prefix(device_id)
  526. # if len(keys) > 0:
  527. # # 需要判断是否有匹配的值, 没有的话会报错
  528. # for key in keys:
  529. # redis_client.delete(key)
  530. # loggerKit.info(f"clear {device_id} keys success...")
  531. # else:
  532. # loggerKit.info(f"{device_id} keys none ...")