| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- """
- 懂车帝养号
- 随机浏览若页面
- """
- import random
- import time
- # import numpy as np
- from func.action_func import del_key_vague
- from scene.oprator.atom_data import single_click_by_control, swipe_screen, stop_app, start_app, back_last_page
- from task.task_job import callback_task
- from tools import loggerKit, redis_client
- def random_browse(task_id, mobile, data):
- loggerKit.info('请求信息:{0}'.format(data))
- device_id = data.get("deviceID")
- perform_action_id = data.get("performActionId")
- result = data.get("result")
- if result is not None:
- """
- 非首个指令
- """
- perform_action_result = result.get("performActionResult")
- if perform_action_result is None:
- return_dict = {
- "data": "",
- "code": -2,
- "message": "fail, performActionResult is null"
- }
- # 回调任务中心
- del_key_vague(device_id)
- callback_task(500, '指令执行失败', task_id, mobile, 0, None)
- return return_dict
- # 指令执行失败
- if perform_action_result == "failure":
- # 回调任务中心
- return_dict = {
- "data": "",
- "code": -2,
- "message": "fail, performActionResult is null"
- }
- del_key_vague(device_id)
- callback_task(500, '指令执行失败', task_id, mobile, 0, None)
- return return_dict
- # 终止指令
- if perform_action_result == "stop":
- # 回调任务中心
- return_dict = {
- "data": "",
- "code": -2,
- "message": "指令被用户终止"
- }
- del_key_vague(device_id)
- callback_task(500, '指令被用户终止', task_id, mobile, 0, None)
- return return_dict
- """
- 每次操作完成后会将对应的操作唯一id存储到redis
- 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
- """
- last_action_id = redis_client.get(device_id + "operate")
- step0 = redis_client.get(f"{device_id}_step0")
- if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
- last_action_id) and perform_action_result == "success":
- action1_id = int(round(time.time() * 1000))
- """
- 发送第1条指令
- 首页随机滑动1~6屏
- """
- # random_num = np.random.choice(range(1, 6), 6)
- # random_scale = random.choice(random_num)
- action1_dict = swipe_screen(action1_id, scale=1, timeout=30, direction='down')
- redis_client.set(device_id + "operate", action1_id)
- redis_client.set(f"{device_id}_step_start", "1")
- redis_client.delete(f"{device_id}_step0")
- loggerKit.info("设备:{0}, action1_id:{1}", device_id, action1_id)
- return action1_dict
- """
- 每次操作完成后会将对应的操作唯一id存储到redis
- 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
- """
- step0 = redis_client.get(f"{device_id}_step_start")
- if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
- last_action_id) and perform_action_result == "success":
- action1_id = int(round(time.time() * 1000))
- """
- 发送第1条指令
- 首页随机滑动1~6屏
- """
- # random_num = np.random.choice(range(1, 6), 6)
- # random_scale = random.choice(random_num)
- random_scale = random.randint(1, 6)
- action1_dict = swipe_screen(action1_id, scale=random_scale, timeout=30)
- redis_client.set(device_id + "operate", action1_id)
- redis_client.set(f"{device_id}_step1", "1")
- redis_client.delete(f"{device_id}_step_start")
- loggerKit.info("设备:{0}, action1_id:{1}", device_id, action1_id)
- return action1_dict
- """
- 搜索关键词
- """
- step1 = redis_client.get(f"{device_id}_step1")
- if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
- last_action_id) and perform_action_result == "success":
- loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
- action2_id = int(round(time.time() * 1000))
- """
- 发送第2条指令
- 点击进入帖子
- """
- action2_dict = single_click_by_control(action2_id, control_id="com.ss.android.auto:id/jum",
- control_ids="com.ss.android.auto:id/s,com.ss.android.auto:id/k2k,"
- "com.ss.android.auto:id/p")
- redis_client.set(device_id + "operate", action2_id)
- redis_client.set(f"{device_id}_step2", "1")
- redis_client.delete(f"{device_id}_step1")
- loggerKit.info("设备:{0}, action2_id:{1}", device_id, action2_id)
- return action2_dict
- # stepA = redis_client.get(f"{device_id}_step2")
- # if stepA is not None and int(stepA) == 1 and last_action_id is not None and int(perform_action_id) == int(
- # last_action_id) and perform_action_result == "invalid operation":
- # """
- # 兼容千人千面
- # """
- # actionA_id = int(round(time.time() * 1000))
- # """
- # 发送第2条指令
- # 点击进入帖子
- # """
- # actionA_dict = single_click_by_control(actionA_id, control_id="com.ss.android.auto:id/s")
- #
- # redis_client.set(device_id + "operate", actionA_id)
- # redis_client.set(f"{device_id}_stepA", "1")
- # redis_client.delete(f"{device_id}_step2")
- #
- # loggerKit.info("设备:{0}, action2_id:{1}", device_id, actionA_id)
- #
- # return actionA_dict
- # stepA1 = redis_client.get(f"{device_id}_stepA")
- # if stepA1 is not None and int(stepA1) == 1 and last_action_id is not None and int(perform_action_id) == int(
- # last_action_id) and perform_action_result == "invalid operation":
- # """
- # 兼容千人千面
- # """
- # actionA1_id = int(round(time.time() * 1000))
- # """
- # 发送第2条指令
- # 点击进入帖子
- # """
- # actionA1_dict = single_click_by_control(actionA1_id, control_id="com.ss.android.auto:id/k2k")
- #
- # redis_client.set(device_id + "operate", actionA1_id)
- # redis_client.set(f"{device_id}_stepA1", "1")
- # redis_client.delete(f"{device_id}_stepA")
- #
- # loggerKit.info("设备:{0}, action2_id:{1}", device_id, actionA1_id)
- #
- # return actionA1_dict
- # stepA2 = redis_client.get(f"{device_id}_stepA1")
- # if stepA2 is not None and int(stepA2) == 1 and last_action_id is not None and int(perform_action_id) == int(
- # last_action_id) and perform_action_result == "invalid operation":
- # """
- # 兼容千人千面
- # """
- # actionA2_id = int(round(time.time() * 1000))
- # """
- # 发送第2条指令
- # 点击进入帖子
- # """
- # actionA2_dict = single_click_by_control(actionA2_id, control_id="com.ss.android.auto:id/p")
- #
- # redis_client.set(device_id + "operate", actionA2_id)
- # redis_client.set(f"{device_id}_stepA2", "1")
- # redis_client.delete(f"{device_id}_stepA1")
- #
- # loggerKit.info("设备:{0}, action2_id:{1}", device_id, actionA2_id)
- #
- # return actionA2_dict
- step2 = redis_client.get(f"{device_id}_step2")
- if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
- last_action_id) and perform_action_result == "success":
- action3_id = int(round(time.time() * 1000))
- """
- 发送第3条指令
- 在帖子中随机滑动1~3屏
- """
- # random_num = np.random.choice(range(1, 3), 3)
- # random_scale = random.choice(random_num)
- random_scale = random.randint(1, 3)
- action3_dict = swipe_screen(action3_id, scale=random_scale, timeout=30)
- redis_client.set(device_id + "operate", action3_id)
- redis_client.set(f"{device_id}_step3", "1")
- redis_client.delete(f"{device_id}_step2")
- # redis_client.delete(f"{device_id}_stepA")
- # redis_client.delete(f"{device_id}_stepA1")
- # redis_client.delete(f"{device_id}_stepA2")
- loggerKit.info("设备:{0}, action3_id:{1}", device_id, action3_id)
- return action3_dict
- step3 = redis_client.get(f"{device_id}_step3")
- if step3 is not None and int(step3) == 1 and (
- last_action_id is not None and int(perform_action_id) == int(last_action_id)
- and perform_action_result == "success"):
- action4_id = int(round(time.time() * 1000))
- """
- 发送第4条指令
- 退出当前帖子
- """
- action1_dict = back_last_page(action4_id)
- redis_client.set(device_id + "operate", action4_id)
- redis_client.set(f"{device_id}_step4", "1")
- redis_client.delete(f"{device_id}_step3")
- loggerKit.info("设备:{0}, action4_id:{1}", device_id, action4_id)
- return action1_dict
- step4 = redis_client.get(f"{device_id}_step4")
- if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int(
- last_action_id) and perform_action_result == "success":
- action5_id = int(round(time.time() * 1000))
- """
- 发送第5条指令
- 首页随机滑动1~6屏
- """
- # random_num = np.random.choice(range(1, 6), 6)
- # random_scale = random.choice(random_num)
- random_scale = random.randint(1, 6)
- action1_dict = swipe_screen(action5_id, scale=random_scale, timeout=30)
- redis_client.set(device_id + "operate", action5_id)
- redis_client.set(f"{device_id}_step5", "1")
- redis_client.delete(f"{device_id}_step4")
- loggerKit.info("设备:{0}, action5_id:{1}", device_id, action5_id)
- return action1_dict
- step5 = redis_client.get(f"{device_id}_step5")
- if step5 is not None and int(step5) == 1 and (last_action_id is not None
- and int(perform_action_id) == int(last_action_id)
- and perform_action_result == "success"):
- loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
- action6_id = int(round(time.time() * 1000))
- """
- 发送第6条指令
- 点击进入帖子
- """
- action2_dict = single_click_by_control(action6_id, control_id="com.ss.android.auto:id/jum",
- control_ids="com.ss.android.auto:id/s,com.ss.android.auto:id/k2k,"
- "com.ss.android.auto:id/p")
- redis_client.set(device_id + "operate", action6_id)
- redis_client.set(f"{device_id}_step6", "1")
- redis_client.delete(f"{device_id}_step5")
- loggerKit.info("设备:{0}, action6_id:{1}", device_id, action6_id)
- return action2_dict
- # stepB = redis_client.get(f"{device_id}_step6")
- # if stepB is not None and int(stepB) == 1 and last_action_id is not None and int(perform_action_id) == int(
- # last_action_id) and perform_action_result == "invalid operation":
- # """
- # 兼容千人千面
- # """
- # actionB_id = int(round(time.time() * 1000))
- # """
- # 发送第2条指令
- # 点击进入帖子
- # """
- # actionB_dict = single_click_by_control(actionB_id, control_id="com.ss.android.auto:id/s")
- #
- # redis_client.set(device_id + "operate", actionB_id)
- # redis_client.set(f"{device_id}_stepB", "1")
- # redis_client.delete(f"{device_id}_step6")
- #
- # loggerKit.info("设备:{0}, action6_id:{1}", device_id, actionB_id)
- #
- # return actionB_dict
- # stepB1 = redis_client.get(f"{device_id}_stepB")
- # if stepB1 is not None and int(stepB1) == 1 and last_action_id is not None and int(perform_action_id) == int(
- # last_action_id) and perform_action_result == "invalid operation":
- # """
- # 兼容千人千面
- # """
- # actionB1_id = int(round(time.time() * 1000))
- # """
- # 发送第2条指令
- # 点击进入帖子
- # """
- # actionB1_dict = single_click_by_control(actionB1_id, control_id="com.ss.android.auto:id/k2k")
- #
- # redis_client.set(device_id + "operate", actionB1_id)
- # redis_client.set(f"{device_id}_stepB1", "1")
- # redis_client.delete(f"{device_id}_stepB")
- #
- # loggerKit.info("设备:{0}, action6_id:{1}", device_id, actionB1_id)
- #
- # return actionB1_dict
- # stepB2 = redis_client.get(f"{device_id}_stepB1")
- # if stepB2 is not None and int(stepB2) == 1 and last_action_id is not None and int(perform_action_id) == int(
- # last_action_id) and perform_action_result == "invalid operation":
- # """
- # 兼容千人千面
- # """
- # actionB2_id = int(round(time.time() * 1000))
- # """
- # 发送第2条指令
- # 点击进入帖子
- # """
- # actionB2_dict = single_click_by_control(actionB2_id, control_id="com.ss.android.auto:id/p")
- #
- # redis_client.set(device_id + "operate", actionB2_id)
- # redis_client.set(f"{device_id}_stepB2", "1")
- # redis_client.delete(f"{device_id}_stepB1")
- #
- # loggerKit.info("设备:{0}, action6_id:{1}", device_id, actionB2_id)
- #
- # return actionB2_dict
- step6 = redis_client.get(f"{device_id}_step6")
- if (step6 is not None and int(step6) == 1 and last_action_id is not None and int(perform_action_id) == int(
- last_action_id)
- and perform_action_result == "success"):
- action7_id = int(round(time.time() * 1000))
- """
- 发送第7条指令
- 在帖子中随机滑动1~3屏
- """
- # random_num = np.random.choice(range(1, 3), 6)
- # random_scale = random.choice(random_num)
- random_scale = random.randint(1, 3)
- action1_dict = swipe_screen(action7_id, scale=random_scale, timeout=30)
- redis_client.set(device_id + "operate", action7_id)
- redis_client.set(f"{device_id}_step7", "1")
- redis_client.delete(f"{device_id}_step6")
- # redis_client.delete(f"{device_id}_stepB")
- # redis_client.delete(f"{device_id}_stepB1")
- # redis_client.delete(f"{device_id}_stepB2")
- loggerKit.info("设备:{0}, action7_id:{1}", device_id, action7_id)
- return action1_dict
- step7 = redis_client.get(f"{device_id}_step7")
- if (step7 is not None and int(step7) == 1 and last_action_id is not None
- and int(perform_action_id) == int(last_action_id) and perform_action_result == "success"):
- action8_id = int(round(time.time() * 1000))
- """
- 发送第8条指令
- 退出当前帖子
- """
- action8_dict = back_last_page(action8_id)
- redis_client.set(device_id + "operate", action8_id)
- redis_client.set(f"{device_id}_step8", "1")
- redis_client.delete(f"{device_id}_step7")
- loggerKit.info("设备:{0}, action8_id:{1}", device_id, action8_id)
- return action8_dict
- step8 = redis_client.get(f"{device_id}_step8")
- if step8 is not None and int(step8) == 1 and (last_action_id is not None
- and int(perform_action_id) == int(last_action_id)
- and perform_action_result == "success"):
- loggerKit.info("设备:{0}, action8_id_mem:{1}", device_id, int(last_action_id))
- action9_id = int(round(time.time() * 1000))
- """
- 发送第9条指令
- 关闭app
- """
- action9_dict = stop_app(action9_id, target_version="7.9.0")
- del_key_vague(device_id)
- loggerKit.info("设备:{0}, action9_id:{1}", device_id, action9_dict)
- # 回调任务中心修改任务状态
- callback_task(None, None, task_id, mobile, 1, None)
- return action9_dict
- else:
- action0_id = int(round(time.time() * 1000))
- """
- 启动指令
- 启动app
- """
- action0_dict = start_app(action0_id, target_version="7.9.0")
- redis_client.set(device_id + "operate", action0_id)
- redis_client.set(f"{device_id}_step0", "1")
- loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
- return action0_dict
|