Compare commits

...

2 Commits

Author SHA1 Message Date
a8a967f770 ai 开始测试 2025-08-28 16:29:16 +08:00
bd9b3c5255 ai 开始测试 2025-08-28 16:24:32 +08:00
2 changed files with 34 additions and 13 deletions

View File

@@ -81,11 +81,11 @@ class ControlUtils(object):
x, y = AiUtils.findImageInScreen("add", udid)
print(x, y)
if x > -1:
print("点赞了")
LogManager.info("点赞了",udid)
session.click(x // scale, y // scale + 50)
return True
else:
print("没有找到目标")
LogManager.info("没有找到目标",udid)
return False
# 点击搜索

View File

@@ -49,7 +49,7 @@ class ScriptManager():
time.sleep(1)
ControlUtils.openTikTok(session, udid)
time.sleep(3)
LogManager.info("养号重启tiktok")
AiUtils.makeUdidDir(udid)
# ========= 主循环 =========
@@ -59,7 +59,15 @@ class ScriptManager():
session.appium_settings({"snapshotMaxDepth": 15})
# 判断当前页面上是否有推荐按钮
el = session(xpath='//XCUIElementTypeButton[@name="top_tabs_recomend"]')
# el = session(xpath='//XCUIElementTypeButton[@name="top_tabs_recomend"]')
# node = session.xpath(
# '//XCUIElementTypeButton[@name="top_tabs_recomend" or @name="推荐" or @label="推荐"]'
# )
el = session.xpath(
'//XCUIElementTypeButton[@name="top_tabs_recomend" or @name="推荐" or @label="推荐"]'
)
if not el.exists:
# 记录日志
LogManager.error("找不到推荐按钮,养号出现问题,重启养号功能", udid=udid)
@@ -70,6 +78,7 @@ class ScriptManager():
LogManager.error("当前页面不是推荐页面,养号出现问题,重启养号功能", udid=udid)
raise Exception("当前页面不是推荐页面,养号出现问题,重启养号功能")
LogManager.info("当前页面是推荐页面,开始养号")
# 重新设置节点的深度,防止手机进行卡顿
session.appium_settings({"snapshotMaxDepth": 0})
@@ -105,7 +114,7 @@ class ScriptManager():
needLike = random.randint(0, 100)
homeButton = AiUtils.findHomeButton(udid)
if homeButton:
print("有首页按钮,查看视频")
LogManager.info("有首页按钮,查看视频", udid)
videoTime = random.randint(5, 15)
time.sleep(videoTime)
@@ -115,16 +124,16 @@ class ScriptManager():
session.appium_settings({"snapshotMaxDepth": 0})
if needLike < 3:
print("点赞")
LogManager.info("进行点赞", udid)
ControlUtils.clickLike(session, udid)
print("继续观看视频")
LogManager.info("继续观看视频", udid)
videoTime = random.randint(10, 30)
time.sleep(videoTime)
print("准备划到下一个视频")
LogManager.info("准备划到下一个视频", udid)
client.swipe_up()
else:
print("找不到首页按钮。出错了")
LogManager.error("找不到首页按钮。出错了", udid)
else:
nextTime = random.randint(1, 5)
time.sleep(nextTime)
@@ -135,8 +144,7 @@ class ScriptManager():
raise e # 抛出给上层,触发重生机制
except Exception as e:
LogManager.error(f"养号出现异常: {e}", udid)
print(f"[{udid}] 养号出现异常,将重启流程: {e}")
LogManager.error(f"[{udid}] 养号出现异常,将重启流程: {e}", udid)
retries += 1
time.sleep(3) # 等待后重生
@@ -171,6 +179,14 @@ class ScriptManager():
raise Exception(f"找不到直播按钮,抛出异常 重新启动")
time.sleep(20)
live_button = session(xpath='//XCUIElementTypeButton[@name="直播"]')
if live_button.exists:
continue
# 下滑一下
client.swipe_up()
# 3) 取分辨率;可选重建 session 规避句柄陈旧
size = session.window_size()
width, height = size.width, size.height
@@ -182,10 +198,15 @@ class ScriptManager():
# 找到一个看直播的时候肯定有的元素,当这个元素没有的时候,就代表当前的页面出现了问题
# 需要抛出异常,重启这个流程
el1 = session.xpath('//XCUIElementTypeOther[@name="GBLFeedRootViewComponent"]')
el2 = session.xpath('//XCUIElementTypeOther[@value="0%"]')
if not session(xpath="//XCUIElementTypeOther[@name='RoomContainer' and @visible='true']").exists:
if not (el1.exists or el2.exists):
print("当前页面不是直播间,重启刷直播")
LogManager.error("当前页面不是直播间,重启刷直播", udid=udid)
raise Exception("当前页面不是直播间")
else:
print("当前页面是直播间,继续刷直播")
# PK 直接划走
if session(xpath='//XCUIElementTypeOther[@name="kGBLInteractionViewMatchScoreBar"]').exists:
@@ -205,7 +226,7 @@ class ScriptManager():
print("✅ 单窗口,(10%概率)开始点赞")
# 随机点赞(仍保留中途保护)
if random.random() >= 0.90:
if random.random() >= 0.97:
print("开始点赞")
for _ in range(random.randint(10, 30)):
# 中途转PK/连麦立即跳过