From a2a1790b70d760247e62876ed0c91a2ab8d9526a Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Wed, 28 Aug 2024 03:19:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 24 +++++++++++++++++++++++- tasks/wechat/__init__.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tasks/wechat/__init__.py diff --git a/main.py b/main.py index 703e4e8..05a0b4f 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,13 @@ import uvicorn from fastapi import FastAPI from pydantic import BaseModel -from typing import Any +from typing import Any, Union import uiautomator2 as u2 import time import random import tasks.douyin +import tasks.wechat app = FastAPI() @@ -104,5 +105,26 @@ async def douyin_task(item: Device): d.xpath("老耗游戏").click() +@app.post("/task/app/wechat/search") +async def wechat_search_task(item: Device): + if item.serial not in devices: + return Response(code=500, msg="设备 {} 不存在".format(item.serial)) + d = devices[item.serial] + tasks.wechat.click_search_btn(d) + + +class WechatSearchInput(Device): + text: str + + +@app.post("/task/app/wechat/search/input") +async def wechat_search_task(item: WechatSearchInput): + if item.serial not in devices: + return Response(code=500, msg="设备 {} 不存在".format(item.serial)) + d = devices[item.serial] + tasks.wechat.click_search_btn(d) + tasks.wechat.input_search_text(d, item.text) + tasks.wechat.click_search_result(d) + if __name__ == '__main__': uvicorn.run('main:app', host='0.0.0.0', port=8000, reload=True) diff --git a/tasks/wechat/__init__.py b/tasks/wechat/__init__.py new file mode 100644 index 0000000..574342c --- /dev/null +++ b/tasks/wechat/__init__.py @@ -0,0 +1,36 @@ +import logging + +from uiautomator2 import Device + + +def click_search_btn(d: Device): + selector = d.xpath('//*[@resource-id="com.tencent.mm:id/h5n"]') + if selector.exists: + selector.click() + else: + logging.warning("未找到组件") + + +def input_search_text(d: Device, text: str): + clear_btn = d.xpath('//*[@resource-id="com.tencent.mm:id/nhn"]') + if clear_btn.exists: + clear_btn.click() + + selector = d.xpath('//*[@resource-id="com.tencent.mm:id/mdd"]') + + if selector.exists: + selector.set_text(text) + else: + logging.warning("未找到组件") + + +def click_search_result(d: Device): + selector = d.xpath('//*[@resource-id="com.tencent.mm:id/kbo"]') + selector.wait(timeout=3) + elements = selector.all() + print(elements) + + if len(elements) > 0: + elements[0].click() + else: + logging.warning("未找到组件")