合并代码

This commit is contained in:
zw
2025-09-05 19:22:52 +08:00
6 changed files with 51 additions and 41 deletions

2
.idea/iOSAI.iml generated
View File

@@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.12 (IOS-AI)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

2
.idea/misc.xml generated
View File

@@ -3,5 +3,5 @@
<component name="Black"> <component name="Black">
<option name="sdkName" value="Python 3.12" /> <option name="sdkName" value="Python 3.12" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (IOS-AI)" project-jdk-type="Python SDK" />
</project> </project>

47
.idea/workspace.xml generated
View File

@@ -5,7 +5,12 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="ai 开始测试"> <list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="ai 开始测试">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/iOSAI.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/iOSAI.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Utils/AiUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/AiUtils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Utils/LogManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/Utils/LogManager.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/script/ScriptManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/script/ScriptManager.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tidevice_entry.py" beforeDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -45,27 +50,27 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;, "ASKED_ADD_EXTERNAL_FILES": "true",
&quot;Python.123.executor&quot;: &quot;Run&quot;, "Python.123.executor": "Run",
&quot;Python.Main.executor&quot;: &quot;Run&quot;, "Python.Main.executor": "Run",
&quot;Python.tidevice_entry.executor&quot;: &quot;Run&quot;, "Python.tidevice_entry.executor": "Run",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "Merging main",
&quot;javascript.nodejs.core.library.configured.version&quot;: &quot;22.18.0&quot;, "javascript.nodejs.core.library.configured.version": "22.18.0",
&quot;javascript.nodejs.core.library.typings.version&quot;: &quot;22.18.1&quot;, "javascript.nodejs.core.library.typings.version": "22.18.1",
&quot;last_opened_file_path&quot;: &quot;F:/company code/AI item/20250820/iOSAI&quot;, "last_opened_file_path": "F:/company code/AI item/20250820/iOSAI",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;settings.editor.selected.configurable&quot;: &quot;com.gitee.ui.GiteeSettingsConfigurable&quot;, "settings.editor.selected.configurable": "com.gitee.ui.GiteeSettingsConfigurable",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="E:\Code\python\iOSAI\resources" /> <recent name="E:\Code\python\iOSAI\resources" />

View File

@@ -294,6 +294,7 @@ class AiUtils(object):
print(f"btn:{btn}") print(f"btn:{btn}")
return cls.findNumber(btn.label) return cls.findNumber(btn.label)
@classmethod @classmethod
def extract_messages_from_xml(cls, xml: str): def extract_messages_from_xml(cls, xml: str):
""" """
@@ -303,15 +304,6 @@ class AiUtils(object):
root = etree.fromstring(xml.encode("utf-8")) root = etree.fromstring(xml.encode("utf-8"))
items = [] items = []
# 判断是否是聊天页面
is_chat_page = False
if root.xpath('//XCUIElementTypeStaticText[contains(@traits, "Header")]'):
is_chat_page = True
elif root.xpath('//XCUIElementTypeCell//XCUIElementTypeOther[@name or @label]'):
is_chat_page = True
if not is_chat_page:
raise Exception("请先进入聊天页面")
# 屏幕宽度 # 屏幕宽度
app = root.xpath('/XCUIElementTypeApplication') app = root.xpath('/XCUIElementTypeApplication')

View File

@@ -180,9 +180,9 @@ class LogManager:
if not log_path.exists(): if not log_path.exists():
return False return False
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
filename = f"{timestamp}_logs.zip" filename = f"{timestamp}_logs.zip"
print(filename)
zip_buf = io.BytesIO() zip_buf = io.BytesIO()
with zipfile.ZipFile(zip_buf, "w", compression=zipfile.ZIP_DEFLATED) as zf: with zipfile.ZipFile(zip_buf, "w", compression=zipfile.ZIP_DEFLATED) as zf:
for p in log_path.rglob("*"): for p in log_path.rglob("*"):

View File

@@ -8,8 +8,9 @@ import os
from Utils.AiUtils import AiUtils from Utils.AiUtils import AiUtils
from Utils.ControlUtils import ControlUtils from Utils.ControlUtils import ControlUtils
from Utils.LogManager import LogManager from Utils.LogManager import LogManager
from Entity.Variables import anchorList, removeModelFromAnchorList, prologueList, anchorWithSession from Entity.Variables import anchorList, removeModelFromAnchorList, anchorWithSession
from Utils.Requester import Requester from Utils.Requester import Requester
import Entity.Variables as ev
# 脚本管理类 # 脚本管理类
@@ -313,6 +314,10 @@ class ScriptManager():
ControlUtils.clickBack(session) ControlUtils.clickBack(session)
time.sleep(2) time.sleep(2)
print("循环条件1", not event.is_set())
print("循环条件2", len(anchorList) > 0)
print("总循环条件", not event.is_set() and len(anchorList) > 0)
# 循环条件。1、 循环关闭 2、 数据处理完毕 # 循环条件。1、 循环关闭 2、 数据处理完毕
while not event.is_set() and len(anchorList) > 0: while not event.is_set() and len(anchorList) > 0:
@@ -452,12 +457,23 @@ class ScriptManager():
# 查找聊天界面中的输入框节点 # 查找聊天界面中的输入框节点
chatInput = session.xpath("//TextView") chatInput = session.xpath("//TextView")
if chatInput.exists: if chatInput.exists:
print("找到输入框了, 准备发送一条打招呼消息") print("找到输入框了, 准备发送一条打招呼消息")
LogManager.method_info("找到输入框了, 准备发送一条打招呼消息", "关注打招呼", udid) LogManager.method_info("找到输入框了, 准备发送一条打招呼消息", "关注打招呼", udid)
print("打招呼的数据", ev.prologueList)
# 准备打招呼的文案 # 准备打招呼的文案
text = random.choice(prologueList) text = random.choice(ev.prologueList)
# 翻译成主播国家的语言
msg = Requester.translation(text, anchorCountry) isContainChniese = AiUtils.contains_chinese(text)
if isContainChniese:
# 翻译成主播国家的语言
msg = Requester.translation(text, anchorCountry)
else:
msg = text
# 准备发送一条信息 # 准备发送一条信息
chatInput.click() chatInput.click()
time.sleep(2) time.sleep(2)
@@ -487,8 +503,6 @@ class ScriptManager():
print("即将要回复消息") print("即将要回复消息")
LogManager.method_info("即将要回复消息", "关注打招呼", udid) LogManager.method_info("即将要回复消息", "关注打招呼", udid)
if needReply: if needReply:
print("如果需要回复主播消息。走此逻辑") print("如果需要回复主播消息。走此逻辑")
@@ -497,7 +511,6 @@ class ScriptManager():
# 执行回复消息逻辑 # 执行回复消息逻辑
self.monitorMessages(session, udid) self.monitorMessages(session, udid)
homeButton = AiUtils.findHomeButton(udid) homeButton = AiUtils.findHomeButton(udid)
if homeButton.exists: if homeButton.exists:
homeButton.click() homeButton.click()