20250904-初步功能已完成

This commit is contained in:
2025-09-13 01:03:15 +08:00
parent 6da5926b4b
commit 3f5c880c0f
3 changed files with 83 additions and 81 deletions

View File

@@ -145,21 +145,10 @@ class ScriptManager():
LogManager.method_error(f"刷视频过程出现错误,重试", "养号", udid)
raise e # 抛出给上层,触发重生机制
except wda.WDARequestError as e:
print(e)
LogManager.method_info("WDA 内部崩溃nil 插入),准备重启 WDA", "养号", udid)
AiUtils.kill_wda(udid, ev.WdaAppBundleId)
time.sleep(1)
AiUtils.launch_wda(udid, ev.WdaAppBundleId)
except Exception as e:
LogManager.method_error(f"[{udid}] 养号出现异常,将重启流程: {e}", "养号", udid)
retries += 1
LogManager.method_error(f"greetNewFollowers 出现最终异常: {e},准备第 {retries} 次重试", "养号", udid)
time.sleep(3)
if retries:
LogManager.method_info("WDA 连接失败,准备重启 WDA", "养号", udid)
AiUtils.kill_wda(udid, ev.WdaAppBundleId)
time.sleep(1)
AiUtils.launch_wda(udid, ev.WdaAppBundleId)
time.sleep(3) # 等待后重生
# 观看直播
def watchLiveForGrowth(self, udid, event, max_retries=None):
@@ -289,28 +278,16 @@ class ScriptManager():
retries = 0
while not event.is_set():
try:
# AiUtils.pop_aclist_first()
# anchor = AiUtils.pop_aclist_first()
# if not anchor:
# break
self.greetNewFollowers(udid, needReply, event)
except wda.WDARequestError as e:
LogManager.method_info("WDA 内部崩溃nil 插入),准备重启 WDA", "关注打招呼", udid)
AiUtils.kill_wda(udid, ev.WdaAppBundleId)
time.sleep(1)
AiUtils.launch_wda(udid, ev.WdaAppBundleId)
except Exception as e:
retries += 1
LogManager.method_error(f"greetNewFollowers 出现最终异常: {e},准备第 {retries} 次重试", "关注打招呼",
udid)
LogManager.method_error(f"greetNewFollowers 出现异常: {e},准备第 {retries} 次重试", "关注打招呼", udid)
time.sleep(3)
if retries % 5 == 0:
LogManager.method_info("WDA 连接失败,准备重启 WDA", "关注打招呼", udid)
AiUtils.kill_wda(udid, ev.WdaAppBundleId)
time.sleep(1)
AiUtils.launch_wda(udid, ev.WdaAppBundleId)
LogManager.method_error("greetNewFollowers 重试次数耗尽,任务终止", "关注打招呼", udid)
# 关注打招呼以及回复主播消息
@@ -324,12 +301,12 @@ class ScriptManager():
LogManager.method_info(f"是否要自动回复消息:{needReply}", "关注打招呼", udid)
# 先关闭Tik Tok
ControlUtils.closeTikTok(session, udid)
time.sleep(1)
# 重新打开Tik Tok
ControlUtils.openTikTok(session, udid)
time.sleep(3)
# ControlUtils.closeTikTok(session, udid)
# time.sleep(random.uniform(1.5, 2.5))
#
# # 重新打开Tik Tok
# ControlUtils.openTikTok(session, udid)
# time.sleep(random.uniform(2.5, 3.5))
# 设置查找深度
session.appium_settings({"snapshotMaxDepth": 15})
@@ -342,7 +319,7 @@ class ScriptManager():
for i in range(count):
session.appium_settings({"snapshotMaxDepth": 15})
ControlUtils.clickBack(session)
time.sleep(2)
time.sleep(random.uniform(1.5, 2.5))
LogManager.method_info(f"循环条件1:{not event.is_set()}", "关注打招呼", udid)
LogManager.method_info(f"循环条件2:{len(anchorList) > 0}", "关注打招呼", udid)
@@ -355,7 +332,7 @@ class ScriptManager():
anchor = AiUtils.pop_aclist_first()
if not anchor:
LogManager.method_info(f"数据库中的数据不足", "关注打招呼", udid)
time.sleep(30)
time.sleep(random.uniform(25, 35))
continue
aid = anchor["anchorId"]
@@ -364,6 +341,8 @@ class ScriptManager():
# 点击搜索按钮
ControlUtils.clickSearch(session)
# 强制刷新session
session.appium_settings({"snapshotMaxDepth": 15})
@@ -379,7 +358,7 @@ class ScriptManager():
print(f"找不到输入框")
input.clear_text()
time.sleep(1)
time.sleep(random.uniform(1, 2))
# 输入主播id
input.set_text(f"{aid or '暂无数据'}\n")
@@ -399,11 +378,11 @@ class ScriptManager():
session.appium_settings({"snapshotMaxDepth": 15})
continue
time.sleep(2)
time.sleep(random.uniform(1.5, 2.5))
# 找到并点击第一个视频
cellClickResult, workCount = ControlUtils.clickFirstVideoFromDetailPage(session)
time.sleep(2)
time.sleep(random.uniform(1.5, 2.5))
# 观看主播视频
def viewAnchorVideo(workCount):
@@ -416,12 +395,12 @@ class ScriptManager():
count = workCount
while count != 0:
time.sleep(5)
time.sleep(random.uniform(3, 6))
img = client.screenshot()
time.sleep(1)
time.sleep(random.uniform(0.5, 2))
# filePath = f"resources/{udid}/bgv.png"
base_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) # 当前脚本目录的上一级
filePath = os.path.join(base_dir, "resources", udid, "bgv.png")
dirPath = os.path.dirname(filePath)
@@ -431,7 +410,7 @@ class ScriptManager():
img.save(filePath)
LogManager.method_info("保存屏幕图像成功", "关注打招呼", udid)
time.sleep(2)
time.sleep(random.uniform(1.5, 2.5))
# 查找add图标
r = ControlUtils.clickLike(session, udid)
@@ -508,13 +487,13 @@ class ScriptManager():
# 准备发送一条信息
chatInput.click()
time.sleep(2)
time.sleep(random.uniform(1.5, 2.5))
# 发送消息
chatInput.set_text(f"{msg or '暂无数据'}\n")
# input.set_text(f"{aid or '暂无数据'}\n")
time.sleep(1)
time.sleep(random.uniform(1, 2))
else:
print("无法发送信息")
@@ -524,11 +503,28 @@ class ScriptManager():
# removeModelFromAnchorList(anchor)
goBack(1)
session.appium_settings({"snapshotMaxDepth": 25})
# 点击关注按钮
followButton = AiUtils.getFollowButton(session)
if followButton is not None:
if followButton:
LogManager.method_info("找到关注按钮了", "关注打招呼", udid)
followButton.click()
x, y, w, h = followButton.bounds
# 基础中心
cx = int(x + w / 2)
cy = int(y + h / 2)
# 随机偏移 ±5 px可自己改范围
cx += random.randint(-5, 5)
cy += random.randint(-5, 5)
session.tap(cx - 95 + random.randint(-5, 5), cy)
time.sleep(random.uniform(1.5, 2.5))
# session.tap(cx - 50, cy - 50)
LogManager.method_info(f"关注按钮落点=({cx},{cy})", "关注打招呼", udid)
session.tap(cx, cy) # facebook-wda 需要列表传参
time.sleep(random.uniform(1.5, 2.5))
else:
LogManager.method_info("没找到关注按钮", "关注打招呼", udid)
time.sleep(1)
@@ -589,25 +585,19 @@ class ScriptManager():
time.sleep(2)
ControlUtils.openTikTok(session, udid)
time.sleep(3)
retries = 0
while not event.is_set():
try:
# 调用检测消息的方法
self.monitorMessages(session, udid)
except wda.WDARequestError as e:
LogManager.method_info("WDA 内部崩溃nil 插入),准备重启 WDA", "养号", udid)
AiUtils.kill_wda(udid, ev.WdaAppBundleId)
time.sleep(1)
AiUtils.launch_wda(udid, ev.WdaAppBundleId)
except Exception as e:
retries += 1
LogManager.method_error(f"greetNewFollowers 出现最终异常: {e},准备第 {retries} 次重试", "养号", udid)
LogManager.method_error(f"监控消息 出现异常: {e},重新启动监控直播", "检测消息", udid)
# 出现异常时,稍等再重启 TikTok 并重试
ControlUtils.closeTikTok(session, udid)
time.sleep(2)
ControlUtils.openTikTok(session, udid)
time.sleep(3)
if retries % 5 == 0:
LogManager.method_info("WDA 连接失败,准备重启 WDA", "养号", udid)
AiUtils.kill_wda(udid, ev.WdaAppBundleId)
time.sleep(1)
AiUtils.launch_wda(udid, ev.WdaAppBundleId)
continue # 重新进入 while 循环,调用 monitorMessages
# 检查未读消息并回复
def monitorMessages(self, session, udid):