微信 测试

This commit is contained in:
shikong 2024-08-28 03:19:41 +08:00
parent 1ad2dc52be
commit a2a1790b70
Signed by: Shikong
GPG Key ID: BD85FF18B373C341
2 changed files with 59 additions and 1 deletions

24
main.py
View File

@ -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)

36
tasks/wechat/__init__.py Normal file
View File

@ -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("未找到组件")