微信 好友消息 和已发送 消息读取
This commit is contained in:
parent
f2e6c5ec37
commit
4ee38b642f
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
15
.idea/git_toolbox_prj.xml
Normal file
15
.idea/git_toolbox_prj.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GitToolBoxProjectSettings">
|
||||||
|
<option name="commitMessageIssueKeyValidationOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
<option name="commitMessageValidationEnabledOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/misc.xml
Normal file
8
.idea/misc.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.10" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="graalvm-17" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/uiautomator2.iml" filepath="$PROJECT_DIR$/.idea/uiautomator2.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
9
.idea/uiautomator2.iml
Normal file
9
.idea/uiautomator2.iml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -18,15 +18,17 @@ class WechatSearchInput(Device):
|
|||||||
input_text: str
|
input_text: str
|
||||||
|
|
||||||
|
|
||||||
@router.post("/search/input")
|
@router.post("/search/chat")
|
||||||
async def wechat_search_task(item: WechatSearchInput):
|
async def wechat_search_task(item: WechatSearchInput):
|
||||||
if item.serial not in devices:
|
if item.serial not in devices:
|
||||||
return Response(code=500, msg="设备 {} 不存在".format(item.serial))
|
return Response(code=500, msg="设备 {} 不存在".format(item.serial))
|
||||||
d = devices[item.serial]
|
d = devices[item.serial]
|
||||||
|
d.app_start("com.tencent.mm")
|
||||||
|
|
||||||
tasks.wechat.click_search_btn(d)
|
tasks.wechat.click_search_btn(d)
|
||||||
tasks.wechat.input_search_text(d, item.search_keyword)
|
tasks.wechat.input_search_text(d, item.search_keyword)
|
||||||
tasks.wechat.click_search_result(d)
|
tasks.wechat.click_search_result(d)
|
||||||
tasks.wechat.get_last_chat_text(d)
|
print(tasks.wechat.get_last_friend_text_msg(d))
|
||||||
# tasks.wechat.input_chat_text(d, time.strftime("[AI] %Y-%m-%d %H:%M:%S", time.localtime()))
|
# 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)
|
tasks.wechat.input_chat_text(d, item.input_text)
|
||||||
|
|
||||||
@ -36,4 +38,5 @@ def wechat_launch(item: Device):
|
|||||||
return Response(code=500, msg="设备 {} 不存在".format(item.serial))
|
return Response(code=500, msg="设备 {} 不存在".format(item.serial))
|
||||||
d = devices[item.serial]
|
d = devices[item.serial]
|
||||||
|
|
||||||
d.app_start("com.tencent.mm")
|
d.app_start("com.tencent.mm")
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ def click_search_btn(d: Device):
|
|||||||
selector.click()
|
selector.click()
|
||||||
else:
|
else:
|
||||||
logging.warning("未找到组件")
|
logging.warning("未找到组件")
|
||||||
|
d.press("back")
|
||||||
|
click_search_btn(d)
|
||||||
|
|
||||||
|
|
||||||
def input_search_text(d: Device, text: str):
|
def input_search_text(d: Device, text: str):
|
||||||
@ -50,11 +52,38 @@ def input_chat_text(d: Device, text: str):
|
|||||||
selector.click()
|
selector.click()
|
||||||
|
|
||||||
|
|
||||||
def get_last_chat_text(d: Device):
|
|
||||||
selector = (d.xpath('//*[@resource-id="com.tencent.mm:id/bn1"]')
|
|
||||||
.child('//*[@resource-id="com.tencent.mm:id/bkl"]'))
|
|
||||||
elements = selector.all()
|
|
||||||
|
|
||||||
if len(elements) > 0:
|
|
||||||
last_element = elements[-1]
|
def get_friend_text_msgs(d: Device):
|
||||||
print(last_element.text)
|
selector = d.xpath('//*[@resource-id="com.tencent.mm:id/bp0"]/android.widget.RelativeLayout')
|
||||||
|
|
||||||
|
elements = selector.all()
|
||||||
|
msg = []
|
||||||
|
for item in elements:
|
||||||
|
# 好友消息
|
||||||
|
el = item.elem.xpath("android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView")
|
||||||
|
if len(el) > 0 :
|
||||||
|
msg.append(el[0].get("text"))
|
||||||
|
|
||||||
|
return msg
|
||||||
|
|
||||||
|
def get_last_friend_text_msg(d: Device):
|
||||||
|
msgs = get_friend_text_msgs(d)
|
||||||
|
return msgs[-1] if len(msgs) > 0 else None
|
||||||
|
|
||||||
|
def get_my_text_msgs(d: Device):
|
||||||
|
selector = d.xpath('//*[@resource-id="com.tencent.mm:id/bp0"]/android.widget.RelativeLayout')
|
||||||
|
|
||||||
|
elements = selector.all()
|
||||||
|
msg = []
|
||||||
|
for item in elements:
|
||||||
|
# 自己的消息
|
||||||
|
el = item.elem.xpath("android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]android.widget.TextView")
|
||||||
|
if len(el) > 0 :
|
||||||
|
msg.append(el[0].get("text"))
|
||||||
|
|
||||||
|
return msg
|
||||||
|
|
||||||
|
def get_last_my_text_msg(d: Device):
|
||||||
|
msgs = get_friend_text_msgs(d)
|
||||||
|
return msgs[-1] if len(msgs) > 0 else None
|
Loading…
Reference in New Issue
Block a user