增加定时重加设备逻辑
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -3,5 +3,5 @@
|
|||||||
<component name="Black">
|
<component name="Black">
|
||||||
<option name="sdkName" value="Python 3.12 (AI-IOS)" />
|
<option name="sdkName" value="Python 3.12 (AI-IOS)" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="IOSAI" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
||||||
@@ -116,6 +116,45 @@ class DeviceInfo:
|
|||||||
self._iproxy_path = self._find_iproxy()
|
self._iproxy_path = self._find_iproxy()
|
||||||
LogManager.info("DeviceInfo 初始化完成", udid="system")
|
LogManager.info("DeviceInfo 初始化完成", udid="system")
|
||||||
print("[Init] DeviceInfo 初始化完成")
|
print("[Init] DeviceInfo 初始化完成")
|
||||||
|
# 延迟执行删除设备方法
|
||||||
|
threading.Thread(target=self.readdDevice).start()
|
||||||
|
|
||||||
|
# 清空所有设备
|
||||||
|
def readdDevice(self):
|
||||||
|
print("开始自动删除设备")
|
||||||
|
second = 0
|
||||||
|
while True:
|
||||||
|
second += 1
|
||||||
|
if second == 3555:
|
||||||
|
with self._lock:
|
||||||
|
# 先拍一张快照,避免“边遍历边修改”
|
||||||
|
udids = list(self._models.keys())
|
||||||
|
for udid in udids:
|
||||||
|
print(f"[Remove] 正在移除设备 {udid}")
|
||||||
|
# 以 udid 为主键,逐个 pop
|
||||||
|
model = self._models.pop(udid, None)
|
||||||
|
proc = self._iproxy.pop(udid, None)
|
||||||
|
self._port_by_udid.pop(udid, None)
|
||||||
|
self._first_seen.pop(udid, None)
|
||||||
|
self._last_seen.pop(udid, None)
|
||||||
|
# 安全结束进程
|
||||||
|
self._kill(proc)
|
||||||
|
# 组一个“下线通知”的占位模型
|
||||||
|
if model is None:
|
||||||
|
model = DeviceModel(
|
||||||
|
deviceId=udid, screenPort=-1, width=0, height=0, scale=0.0, type=2
|
||||||
|
)
|
||||||
|
# 标记为“已移除/离线”
|
||||||
|
model.type = 2
|
||||||
|
model.ready = False
|
||||||
|
model.screenPort = -1
|
||||||
|
# 通知上层
|
||||||
|
self._manager_send(model)
|
||||||
|
print(f"[Remove] 已移除设备 {udid}")
|
||||||
|
second = 0
|
||||||
|
print(f"[Remove] 设备移除完成,总数: {len(udids)}")
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
def listen(self):
|
def listen(self):
|
||||||
LogManager.method_info("进入主循环", "listen", udid="system")
|
LogManager.method_info("进入主循环", "listen", udid="system")
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -52,7 +52,6 @@ class ScriptManager():
|
|||||||
|
|
||||||
self.initialized = True # 标记已初始化
|
self.initialized = True # 标记已初始化
|
||||||
|
|
||||||
# ========= 评论逻辑 =========
|
|
||||||
def comment_flow(self, filePath, session, udid, recomend_cx, recomend_cy):
|
def comment_flow(self, filePath, session, udid, recomend_cx, recomend_cy):
|
||||||
"""评论一条龙:点评论框->输入->发送->返回"""
|
"""评论一条龙:点评论框->输入->发送->返回"""
|
||||||
|
|
||||||
@@ -80,6 +79,8 @@ class ScriptManager():
|
|||||||
|
|
||||||
coord2 = OCRUtils.find_template(str(self.comment_add_dir), filePath)
|
coord2 = OCRUtils.find_template(str(self.comment_add_dir), filePath)
|
||||||
|
|
||||||
|
click_count = False
|
||||||
|
|
||||||
if coord2: # 二判命中
|
if coord2: # 二判命中
|
||||||
LogManager.method_info(f"方案1", "养号", udid)
|
LogManager.method_info(f"方案1", "养号", udid)
|
||||||
cx2, cy2 = coord2[0]
|
cx2, cy2 = coord2[0]
|
||||||
@@ -88,6 +89,8 @@ class ScriptManager():
|
|||||||
session.send_keys(f"{single_comment}\n")
|
session.send_keys(f"{single_comment}\n")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
LogManager.method_info("评论成功", "养号", udid)
|
LogManager.method_info("评论成功", "养号", udid)
|
||||||
|
click_count = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
LogManager.method_info(f"方案2", "养号", udid)
|
LogManager.method_info(f"方案2", "养号", udid)
|
||||||
@@ -101,13 +104,19 @@ class ScriptManager():
|
|||||||
session.send_keys(f"{single_comment}\n")
|
session.send_keys(f"{single_comment}\n")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
LogManager.method_info("评论成功", "养号", udid)
|
LogManager.method_info("评论成功", "养号", udid)
|
||||||
|
click_count = True
|
||||||
|
|
||||||
# 点返回/取消按钮:优先用推荐按钮坐标,没有就兜底 100,100
|
# 点返回/取消按钮:优先用推荐按钮坐标,没有就兜底 100,100
|
||||||
tap_x = int(recomend_cx) if recomend_cx else 100
|
tap_x = int(recomend_cx) if recomend_cx else 100
|
||||||
tap_y = int(recomend_cy) if recomend_cy else 100
|
tap_y = int(recomend_cy) if recomend_cy else 100
|
||||||
session.tap(tap_x, tap_y)
|
if click_count:
|
||||||
time.sleep(1)
|
print("点击一次")
|
||||||
session.tap(tap_x, tap_y)
|
session.tap(tap_x, tap_y)
|
||||||
|
else:
|
||||||
|
print("点击两次")
|
||||||
|
session.tap(tap_x, tap_y)
|
||||||
|
time.sleep(1)
|
||||||
|
session.tap(tap_x, tap_y)
|
||||||
|
|
||||||
# 养号
|
# 养号
|
||||||
def growAccount(self, udid, isComment, event, is_monitoring=False):
|
def growAccount(self, udid, isComment, event, is_monitoring=False):
|
||||||
@@ -223,6 +232,7 @@ class ScriptManager():
|
|||||||
|
|
||||||
if isComment and random.random() > 0.70:
|
if isComment and random.random() > 0.70:
|
||||||
self.comment_flow(filePath, session, udid, recomend_cx, recomend_cy)
|
self.comment_flow(filePath, session, udid, recomend_cx, recomend_cy)
|
||||||
|
event.wait(timeout=2)
|
||||||
|
|
||||||
videoTime = random.randint(15, 30)
|
videoTime = random.randint(15, 30)
|
||||||
for _ in range(videoTime):
|
for _ in range(videoTime):
|
||||||
@@ -455,6 +465,8 @@ class ScriptManager():
|
|||||||
for i in range(count):
|
for i in range(count):
|
||||||
LogManager.method_info(f"返回上一步", "关注打招呼", udid)
|
LogManager.method_info(f"返回上一步", "关注打招呼", udid)
|
||||||
session.appium_settings({"snapshotMaxDepth": 15})
|
session.appium_settings({"snapshotMaxDepth": 15})
|
||||||
|
source = session.source()
|
||||||
|
LogManager.method_info(f"返回按钮的节点:{source}","返回节点", udid)
|
||||||
ControlUtils.clickBack(session)
|
ControlUtils.clickBack(session)
|
||||||
event.wait(timeout=2)
|
event.wait(timeout=2)
|
||||||
|
|
||||||
@@ -543,7 +555,7 @@ class ScriptManager():
|
|||||||
session.appium_settings({"snapshotMaxDepth": 15})
|
session.appium_settings({"snapshotMaxDepth": 15})
|
||||||
continue
|
continue
|
||||||
|
|
||||||
event.wait(timeout=2)
|
event.wait(timeout=5)
|
||||||
# 找到并点击第一个视频
|
# 找到并点击第一个视频
|
||||||
cellClickResult, workCount = ControlUtils.clickFirstVideoFromDetailPage(session)
|
cellClickResult, workCount = ControlUtils.clickFirstVideoFromDetailPage(session)
|
||||||
|
|
||||||
@@ -599,6 +611,7 @@ class ScriptManager():
|
|||||||
# 使用OCR进行评论
|
# 使用OCR进行评论
|
||||||
if isComment:
|
if isComment:
|
||||||
self.comment_flow(filePath, session, udid, 100, 100)
|
self.comment_flow(filePath, session, udid, 100, 100)
|
||||||
|
event.wait(timeout=2)
|
||||||
|
|
||||||
if count != 0:
|
if count != 0:
|
||||||
ControlUtils.swipe_up(udid)
|
ControlUtils.swipe_up(udid)
|
||||||
@@ -645,23 +658,32 @@ class ScriptManager():
|
|||||||
print("找到输入框了, 准备发送一条打招呼消息")
|
print("找到输入框了, 准备发送一条打招呼消息")
|
||||||
LogManager.method_info("找到输入框了, 准备发送一条打招呼消息", "关注打招呼", udid)
|
LogManager.method_info("找到输入框了, 准备发送一条打招呼消息", "关注打招呼", udid)
|
||||||
|
|
||||||
print("打招呼的数据", ev.prologueList)
|
|
||||||
# LogManager.method_info(f"传递的打招呼的数据:{ev.prologueList}", "关注打招呼", udid)
|
# LogManager.method_info(f"传递的打招呼的数据:{ev.prologueList}", "关注打招呼", udid)
|
||||||
|
|
||||||
|
|
||||||
# 取出国家进行对应国家语言代码
|
# 取出国家进行对应国家语言代码
|
||||||
anchorCountry_code = CountryLanguageMapper.get_language_code(anchorCountry)
|
anchorCountry_code = CountryLanguageMapper.get_language_code(anchorCountry)
|
||||||
print(anchorCountry_code)
|
|
||||||
|
|
||||||
|
|
||||||
print("存储的是:",ev.prologueList)
|
|
||||||
|
LogManager.method_info(f"获取的语言代码是:{ev.prologueList}","关注打招呼",udid)
|
||||||
|
|
||||||
|
LogManager.method_info(f"存储的打招呼语句是:{ev.prologueList}","关注打招呼",udid)
|
||||||
|
|
||||||
# 判断对应的语言代码是否在传入的字典中
|
# 判断对应的语言代码是否在传入的字典中
|
||||||
if anchorCountry_code in ev.prologueList:
|
if anchorCountry_code in ev.prologueList:
|
||||||
|
|
||||||
|
LogManager.method_info(f"在存储的字典中 打招呼语句是:{ev.prologueList}", "关注打招呼", udid)
|
||||||
|
|
||||||
# 进行原本的进行传入
|
# 进行原本的进行传入
|
||||||
privateMessageList = ev.prologueList[anchorCountry_code]
|
privateMessageList = ev.prologueList[anchorCountry_code]
|
||||||
|
|
||||||
|
|
||||||
needTranslate = False
|
needTranslate = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
LogManager.method_info(f"不在存储的字典中 打招呼语句是:{ev.prologueList}", "关注打招呼", udid)
|
||||||
# 需要翻译
|
# 需要翻译
|
||||||
privateMessageList = ev.prologueList['yolo']
|
privateMessageList = ev.prologueList['yolo']
|
||||||
needTranslate = True # 使用yolo必须翻译
|
needTranslate = True # 使用yolo必须翻译
|
||||||
@@ -1315,6 +1337,7 @@ class ScriptManager():
|
|||||||
|
|
||||||
sel = session.xpath("//TextView")
|
sel = session.xpath("//TextView")
|
||||||
if anchor_name not in anchorWithSession:
|
if anchor_name not in anchorWithSession:
|
||||||
|
print("没有记忆")
|
||||||
|
|
||||||
# 如果是第一次发消息(没有sessionId的情况)
|
# 如果是第一次发消息(没有sessionId的情况)
|
||||||
LogManager.method_info(f"第一次发消息:{anchor_name},没有记忆 开始请求ai", "检测消息", udid)
|
LogManager.method_info(f"第一次发消息:{anchor_name},没有记忆 开始请求ai", "检测消息", udid)
|
||||||
@@ -1328,15 +1351,14 @@ class ScriptManager():
|
|||||||
if last_out:
|
if last_out:
|
||||||
text = last_out
|
text = last_out
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if sel.exists:
|
if sel.exists:
|
||||||
sel.click() # 聚焦
|
sel.click() # 聚焦
|
||||||
event.wait(timeout=1)
|
event.wait(timeout=1)
|
||||||
sel.clear_text()
|
sel.clear_text()
|
||||||
|
|
||||||
LogManager.method_info(f"发送的消息,检测不到对方发送的消息,不走ai:{text or '暂无数据'}", "检测消息",
|
LogManager.method_info(
|
||||||
udid)
|
f"发送的消息,检测不到对方发送的消息,不走ai:{text or '暂无数据'}", "检测消息",
|
||||||
|
udid)
|
||||||
|
|
||||||
sel.set_text(f"{text or '暂无数据'}\n")
|
sel.set_text(f"{text or '暂无数据'}\n")
|
||||||
else:
|
else:
|
||||||
@@ -1352,42 +1374,59 @@ class ScriptManager():
|
|||||||
sel.click() # 聚焦
|
sel.click() # 聚焦
|
||||||
event.wait(timeout=1)
|
event.wait(timeout=1)
|
||||||
sel.clear_text()
|
sel.clear_text()
|
||||||
LogManager.method_info(f"发送的消息,检测到对方发送的消息,进行走ai(没记忆):{aiResult or '暂无数据'}", "检测消息",
|
LogManager.method_info(
|
||||||
udid)
|
f"发送的消息,检测到对方发送的消息,进行走ai(没记忆):{aiResult or '暂无数据'}",
|
||||||
|
"检测消息",
|
||||||
|
udid)
|
||||||
sel.set_text(f"{aiResult or '暂无数据'}\n")
|
sel.set_text(f"{aiResult or '暂无数据'}\n")
|
||||||
else:
|
else:
|
||||||
LogManager.method_error("找不到输入框,重启", "检测消息", udid)
|
LogManager.method_error("找不到输入框,重启", "检测消息", udid)
|
||||||
raise Exception("找不到输入框,重启")
|
raise Exception("找不到输入框,重启")
|
||||||
else:
|
else:
|
||||||
|
print("有记忆")
|
||||||
|
|
||||||
LogManager.method_info(f"不是一次发消息:{anchor_name},有记忆", "检测消息", udid)
|
LogManager.method_info(f"不是一次发消息:{anchor_name},有记忆", "检测消息", udid)
|
||||||
# 如果不是第一次发消息(证明存储的有sessionId)
|
# 如果不是第一次发消息(证明存储的有sessionId)
|
||||||
sessionId = anchorWithSession[anchor_name]
|
sessionId = anchorWithSession[anchor_name]
|
||||||
|
|
||||||
# TODO: user后续添加,暂时写死
|
if last_in is None:
|
||||||
|
last_in = "ok"
|
||||||
|
if sel.exists:
|
||||||
|
sel.click() # 聚焦
|
||||||
|
event.wait(timeout=1)
|
||||||
|
sel.clear_text()
|
||||||
|
LogManager.method_info(
|
||||||
|
f"发送的消息,检测到对方发送的消息,进行走ai(有记忆):{last_in or '暂无数据'}",
|
||||||
|
"检测消息",
|
||||||
|
udid)
|
||||||
|
sel.set_text(f"{last_in or '暂无数据'}\n")
|
||||||
|
else:
|
||||||
|
|
||||||
LogManager.method_info(f"向ai发送的参数: 文本为:{last_in}", "检测消息", udid)
|
# TODO: user后续添加,暂时写死
|
||||||
|
|
||||||
aiResult, sessionId = Requester.chatToAi(
|
LogManager.method_info(f"向ai发送的参数: 文本为:{last_in}", "检测消息", udid)
|
||||||
{"query": last_in, "conversation_id": sessionId, "user": "1"})
|
|
||||||
|
|
||||||
if sel.exists:
|
aiResult, sessionId = Requester.chatToAi(
|
||||||
sel.click() # 聚焦
|
{"query": last_in, "conversation_id": sessionId, "user": "1"})
|
||||||
event.wait(timeout=1)
|
|
||||||
sel.clear_text()
|
|
||||||
LogManager.method_info(
|
|
||||||
f"发送的消息,检测到对方发送的消息,进行走ai(有记忆):{aiResult or '暂无数据'}",
|
|
||||||
"检测消息",
|
|
||||||
udid)
|
|
||||||
sel.set_text(f"{aiResult or '暂无数据'}\n")
|
|
||||||
|
|
||||||
LogManager.method_info(f"存储的sessionId:{anchorWithSession}", "检测消息", udid)
|
if sel.exists:
|
||||||
event.wait(timeout=1)
|
sel.click() # 聚焦
|
||||||
# 返回
|
event.wait(timeout=1)
|
||||||
ControlUtils.clickBack(session)
|
sel.clear_text()
|
||||||
|
LogManager.method_info(
|
||||||
|
f"发送的消息,检测到对方发送的消息,进行走ai(有记忆):{aiResult or '暂无数据'}",
|
||||||
|
"检测消息",
|
||||||
|
udid)
|
||||||
|
sel.set_text(f"{aiResult or '暂无数据'}\n")
|
||||||
|
|
||||||
# 重新回到收件箱页面后,强制刷新节点
|
LogManager.method_info(f"存储的sessionId:{anchorWithSession}", "检测消息", udid)
|
||||||
session.appium_settings({"snapshotMaxDepth": 25})
|
event.wait(timeout=1)
|
||||||
event.wait(timeout=1)
|
# 返回
|
||||||
|
ControlUtils.clickBack(session)
|
||||||
|
|
||||||
|
# 重新回到收件箱页面后,强制刷新节点
|
||||||
|
session.appium_settings({"snapshotMaxDepth": 25})
|
||||||
|
event.wait(timeout=1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 如果 2 秒内找不到,会抛异常
|
# 如果 2 秒内找不到,会抛异常
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user