From 8050d8c14cfdfdbd9195985398665ad2edca9f4f Mon Sep 17 00:00:00 2001
From: zhangkai <2403741920@qq.com>
Date: Fri, 5 Sep 2025 16:33:03 +0800
Subject: [PATCH 1/2] =?UTF-8?q?20250904-=E5=88=9D=E6=AD=A5=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=E5=B7=B2=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/workspace.xml | 34 ++++++------
Module/FlaskService.py | 16 ++++--
Utils/AiUtils.py | 114 -----------------------------------------
Utils/LogManager.py | 4 +-
tidevice_entry.py | 45 ++++++++++++++++
5 files changed, 77 insertions(+), 136 deletions(-)
create mode 100644 tidevice_entry.py
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a3a88ba..cd899f8 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,19 +4,12 @@
-
-
-
-
-
-
+
+
-
-
-
@@ -73,7 +66,7 @@
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
- "settings.editor.selected.configurable": "com.gitee.ui.GiteeSettingsConfigurable",
+ "settings.editor.selected.configurable": "vcs.Git",
"vue.rearranger.settings.migration": "true"
}
}
@@ -188,7 +181,9 @@
-
+
+
+
@@ -198,7 +193,15 @@
1756303135240
-
+
+
+ 1756985736631
+
+
+
+ 1756985736631
+
+
@@ -221,7 +224,8 @@
-
+
+
@@ -229,10 +233,10 @@
-
+
-
+
\ No newline at end of file
diff --git a/Module/FlaskService.py b/Module/FlaskService.py
index d267a95..c464536 100644
--- a/Module/FlaskService.py
+++ b/Module/FlaskService.py
@@ -17,8 +17,7 @@ from Entity.ResultData import ResultData
from Utils.ControlUtils import ControlUtils
from Utils.ThreadManager import ThreadManager
from script.ScriptManager import ScriptManager
-from Entity.Variables import anchorList, addModelToAnchorList
-import Entity.Variables
+from Entity.Variables import anchorList, addModelToAnchorList,prologueList
app = Flask(__name__)
CORS(app)
@@ -278,6 +277,7 @@ def getChatTextInfo():
session = client.session()
xml = session.source()
try:
+ print(xml)
result = AiUtils.extract_messages_from_xml(xml)
print(result)
return ResultData(data=result).toJson()
@@ -318,12 +318,18 @@ def upLoadLogFile():
userId = data.get("userId")
tenantId = data.get("tenantId")
ok = LogManager.upload_all_logs("http://47.79.98.113:8101/api/log/upload", token, userId, tenantId)
+
if ok:
- print(123)
return ResultData(data="日志上传成功").toJson()
else:
return ResultData(data="", msg="日志上传失败").toJson()
+# @app.route("/", methods=['POST'])
+# def upLoadLogFile():
+# datas = request.get_json() # 解析 JSON
+# # 先清空打招呼语
+# prologueList.clear()
+# # 添加新的打招呼语句
+# for data in datas:
+# prologueList.append(data)
-if __name__ == '__main__':
- app.run("0.0.0.0", port=5000, debug=True, use_reloader=False)
diff --git a/Utils/AiUtils.py b/Utils/AiUtils.py
index d43a400..1550cf5 100644
--- a/Utils/AiUtils.py
+++ b/Utils/AiUtils.py
@@ -294,109 +294,6 @@ class AiUtils(object):
print(f"btn:{btn}")
return cls.findNumber(btn.label)
- # 获取聊天页面的聊天信息
- # @classmethod
- # def extract_messages_from_xml(cls, xml: str):
- # """
- # 仅返回当前屏幕中“可见的”聊天内容(含时间分隔)
- # """
- # from lxml import etree
- # root = etree.fromstring(xml.encode("utf-8"))
- # 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')
- #
- # screen_w = cls.parse_float(app[0], 'width', 414.0) if app else 414.0
- #
- # # 找 Table 的可见范围
- # table = root.xpath('//XCUIElementTypeTable')
- # if table:
- # table = table[0]
- # table_top = cls.parse_float(table, 'y', 0.0)
- # table_h = cls.parse_float(table, 'height', 0.0)
- # table_bottom = table_top + table_h
- # else:
- # table_top, table_bottom = 0.0, cls.parse_float(app[0], 'height', 736.0) if app else 736.0
- #
- # def in_view(el) -> bool:
- # """元素在聊天区内并且可见"""
- # if el.get('visible') != 'true':
- # return False
- # y = cls.parse_float(el, 'y', -1e9)
- # h = cls.parse_float(el, 'height', 0.0)
- # by = y + h
- # return not (by <= table_top or y >= table_bottom)
- #
- # # 时间分隔
- # for t in root.xpath('//XCUIElementTypeStaticText[contains(@traits, "Header")]'):
- # if not in_view(t):
- # continue
- # txt = (t.get('label') or t.get('name') or t.get('value') or '').strip()
- # if txt:
- # items.append({'type': 'time', 'text': txt, 'y': cls.parse_float(t, 'y')})
- #
- # # 消息气泡
- # EXCLUDES = {'Heart', 'Lol', 'ThumbsUp', '分享发布内容', '视频贴纸标签页', '双击发送表情'}
- #
- # msg_nodes = table.xpath(
- # './/XCUIElementTypeCell[@visible="true"]'
- # '//XCUIElementTypeOther[@visible="true" and (@name or @label) and not(ancestor::XCUIElementTypeCollectionView)]'
- # ) if table is not None else []
- #
- # for o in msg_nodes:
- # text = (o.get('label') or o.get('name') or '').strip()
- # if not text or text in EXCLUDES:
- # continue
- # if not in_view(o):
- # continue
- #
- # # 找所在 Cell
- # cell = o.getparent()
- # while cell is not None and cell.get('type') != 'XCUIElementTypeCell':
- # cell = cell.getparent()
- #
- # x = cls.parse_float(o, 'x')
- # y = cls.parse_float(o, 'y')
- # w = cls.parse_float(o, 'width')
- # right_edge = x + w
- #
- # direction = None
- # # 头像位置判定
- # if cell is not None:
- # avatar_btns = cell.xpath(
- # './/XCUIElementTypeButton[@visible="true" and (@name="图片头像" or @label="图片头像")]')
- # if avatar_btns:
- # ax = cls.parse_float(avatar_btns[0], 'x')
- # direction = 'in' if ax < (screen_w / 2) else 'out'
- # # 右对齐兜底
- # if direction is None:
- # direction = 'out' if right_edge > (screen_w - 20) else 'in'
- #
- # items.append({'type': 'msg', 'dir': direction, 'text': text, 'y': y})
- #
- # # 排序 & 清理
- # items.sort(key=lambda i: i['y'])
- # for it in items:
- # it.pop('y', None)
- # return items
- #
- # @classmethod
- # def parse_float(cls, el, attr, default=0.0):
- # try:
- # return float(el.get(attr, default))
- # except Exception:
- # return default
@classmethod
def extract_messages_from_xml(cls, xml: str):
@@ -407,15 +304,6 @@ class AiUtils(object):
root = etree.fromstring(xml.encode("utf-8"))
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')
@@ -571,5 +459,3 @@ class AiUtils(object):
return t
return ""
-
-# AiUtils.getCurrentScreenSource()
diff --git a/Utils/LogManager.py b/Utils/LogManager.py
index 7233acd..afb11f3 100644
--- a/Utils/LogManager.py
+++ b/Utils/LogManager.py
@@ -267,9 +267,9 @@ class LogManager:
print("[upload_all_logs] 日志目录不存在")
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"
-
+ print(filename)
zip_buf = io.BytesIO()
with zipfile.ZipFile(zip_buf, "w", compression=zipfile.ZIP_DEFLATED) as zf:
for p in log_path.rglob("*"):
diff --git a/tidevice_entry.py b/tidevice_entry.py
new file mode 100644
index 0000000..9d5855b
--- /dev/null
+++ b/tidevice_entry.py
@@ -0,0 +1,45 @@
+# from Utils.Requester import Requester
+#
+#
+# # 获取主播的名称
+# anchor_name = "123"
+#
+# anchorWithSession = {}
+#
+#
+# while True:
+# # 向ai发送信息
+# last_msg_text = input("请输入:")
+#
+#
+# if anchor_name not in anchorWithSession:
+# # 如果是第一次发消息(没有sessionId的情况)
+# response = Requester.chatToAi({"msg": last_msg_text})
+# aiResult = response['result']
+# sessionId = response['session_id']
+#
+# anchorWithSession[anchor_name] = sessionId
+# # 找到输入框,输入ai返回出来的消息
+# print(aiResult)
+#
+# else:
+# # 如果不是第一次发消息(证明存储的有sessionId)
+# sessionId = anchorWithSession[anchor_name]
+# response = Requester.chatToAi({"msg": last_msg_text, "sid": sessionId})
+# aiResult = response['result']
+# print(aiResult)
+import datetime
+
+import wda
+
+udid = "e5ab9d3c548302dca3b1383589ac43eedd41f24e"
+
+client = wda.USBClient(udid)
+session = client.session()
+session.appium_settings({"snapshotMaxDepth": 15})
+
+print(session.source())
+
+
+
+
From 31f0e19b13649f51a5e98ea7baa85375ea2dd891 Mon Sep 17 00:00:00 2001
From: zhangkai <2403741920@qq.com>
Date: Fri, 5 Sep 2025 19:16:14 +0800
Subject: [PATCH 2/2] =?UTF-8?q?20250904-=E5=88=9D=E6=AD=A5=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=E5=B7=B2=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/iOSAI.iml | 2 +-
.idea/misc.xml | 2 +-
.idea/workspace.xml | 75 ++++++++++++++++++++++++-----------------
script/ScriptManager.py | 27 +++++++++++----
tidevice_entry.py | 45 -------------------------
5 files changed, 66 insertions(+), 85 deletions(-)
delete mode 100644 tidevice_entry.py
diff --git a/.idea/iOSAI.iml b/.idea/iOSAI.iml
index f571432..df5cbff 100644
--- a/.idea/iOSAI.iml
+++ b/.idea/iOSAI.iml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index db8786c..c27b771 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,5 +3,5 @@
-
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 33c043d..a4c3660 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,10 +5,8 @@
-
-
-
-
+
+
@@ -48,33 +46,48 @@
- {
+ "keyToString": {
+ "ASKED_ADD_EXTERNAL_FILES": "true",
+ "Python.123.executor": "Run",
+ "Python.Main.executor": "Run",
+ "Python.tidevice_entry.executor": "Run",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "git-widget-placeholder": "main",
+ "javascript.nodejs.core.library.configured.version": "22.18.0",
+ "javascript.nodejs.core.library.typings.version": "22.18.1",
+ "last_opened_file_path": "F:/company code/AI item/20250820/iOSAI",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "com.gitee.ui.GiteeSettingsConfigurable",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -217,15 +230,15 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/script/ScriptManager.py b/script/ScriptManager.py
index 16e8adb..59acb52 100644
--- a/script/ScriptManager.py
+++ b/script/ScriptManager.py
@@ -8,8 +8,9 @@ import os
from Utils.AiUtils import AiUtils
from Utils.ControlUtils import ControlUtils
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
+import Entity.Variables as ev
# 脚本管理类
@@ -313,6 +314,10 @@ class ScriptManager():
ControlUtils.clickBack(session)
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、 数据处理完毕
while not event.is_set() and len(anchorList) > 0:
@@ -452,12 +457,23 @@ class ScriptManager():
# 查找聊天界面中的输入框节点
chatInput = session.xpath("//TextView")
if chatInput.exists:
+
print("找到输入框了, 准备发送一条打招呼消息")
LogManager.method_info("找到输入框了, 准备发送一条打招呼消息", "关注打招呼", udid)
+
+ print("打招呼的数据", ev.prologueList)
+
# 准备打招呼的文案
- text = random.choice(prologueList)
- # 翻译成主播国家的语言
- msg = Requester.translation(text, anchorCountry)
+ text = random.choice(ev.prologueList)
+
+ isContainChniese = AiUtils.contains_chinese(text)
+
+ if isContainChniese:
+ # 翻译成主播国家的语言
+ msg = Requester.translation(text, anchorCountry)
+ else:
+ msg = text
+
# 准备发送一条信息
chatInput.click()
time.sleep(2)
@@ -487,8 +503,6 @@ class ScriptManager():
print("即将要回复消息")
LogManager.method_info("即将要回复消息", "关注打招呼", udid)
-
-
if needReply:
print("如果需要回复主播消息。走此逻辑")
@@ -497,7 +511,6 @@ class ScriptManager():
# 执行回复消息逻辑
self.monitorMessages(session, udid)
-
homeButton = AiUtils.findHomeButton(udid)
if homeButton.exists:
homeButton.click()
diff --git a/tidevice_entry.py b/tidevice_entry.py
deleted file mode 100644
index 9d5855b..0000000
--- a/tidevice_entry.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# from Utils.Requester import Requester
-#
-#
-# # 获取主播的名称
-# anchor_name = "123"
-#
-# anchorWithSession = {}
-#
-#
-# while True:
-# # 向ai发送信息
-# last_msg_text = input("请输入:")
-#
-#
-# if anchor_name not in anchorWithSession:
-# # 如果是第一次发消息(没有sessionId的情况)
-# response = Requester.chatToAi({"msg": last_msg_text})
-# aiResult = response['result']
-# sessionId = response['session_id']
-#
-# anchorWithSession[anchor_name] = sessionId
-# # 找到输入框,输入ai返回出来的消息
-# print(aiResult)
-#
-# else:
-# # 如果不是第一次发消息(证明存储的有sessionId)
-# sessionId = anchorWithSession[anchor_name]
-# response = Requester.chatToAi({"msg": last_msg_text, "sid": sessionId})
-# aiResult = response['result']
-# print(aiResult)
-import datetime
-
-import wda
-
-udid = "e5ab9d3c548302dca3b1383589ac43eedd41f24e"
-
-client = wda.USBClient(udid)
-session = client.session()
-session.appium_settings({"snapshotMaxDepth": 15})
-
-print(session.source())
-
-
-
-