python-uiautomator2/api/wechat.py
2025-02-01 14:41:23 +08:00

39 lines
1.2 KiB
Python

import tasks.wechat
import time
from .base import *
from fastapi import APIRouter
router = APIRouter()
@router.post("/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):
search_keyword: str
input_text: str
@router.post("/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.search_keyword)
tasks.wechat.click_search_result(d)
tasks.wechat.get_last_chat_text(d)
# tasks.wechat.input_chat_text(d, time.strftime("[AI] %Y-%m-%d %H:%M:%S", time.localtime()))
tasks.wechat.input_chat_text(d, item.input_text)
@router.post("/launch")
def wechat_launch(item: Device):
if item.serial not in devices:
return Response(code=500, msg="设备 {} 不存在".format(item.serial))
d = devices[item.serial]
d.app_start("com.tencent.mm")