import tasks.wechat import time import random from .base import * from fastapi import APIRouter router = APIRouter() @router.post("/douyin") async def douyin_task(item: Device): if item.serial not in devices: return Response(code=500, msg="设备 {} 不存在".format(item.serial)) d = devices[item.serial] d.app_start("com.ss.android.ugc.aweme", stop=False) # d.xpath("关闭").wait(timeout=1) width, height = d.window_size() random.seed(time.time()) for i in range(10): start_x = random.randint(0, int(width)) end_x = round(start_x + random.random(), 1) end_y = random.randint(0, int(height / 10)) start_y = round(end_y * 9.75, 1) if start_y - end_y < (height / 3): start_y += round((height / 3), 1) # d.swipe_ext("up", scale=0.95, duration=0.1) print(f"({start_x}, {start_y}) => ({end_x}, {end_y})") d.swipe(start_x, start_y, end_x + random.random(), end_y, duration=0.05 + random.random() * 0.1) time.sleep(5 + random.random() * 2) return Response() @router.post("/test") async def douyin_task(item: Device): if item.serial not in devices: return Response(code=500, msg="设备 {} 不存在".format(item.serial)) d = devices[item.serial] d.app_start("com.ss.android.ugc.aweme", stop=False) tasks.douyin.click_search_icon(d) tasks.douyin.input_search_text(d, "老耗") d.xpath("老耗游戏").click()