20250916-正式上线测试

This commit is contained in:
2025-09-16 14:03:43 +08:00
parent b203579649
commit b91aa99048
3 changed files with 86 additions and 90 deletions

View File

@@ -307,7 +307,7 @@ class ScriptManager():
# 重新打开Tik Tok
ControlUtils.openTikTok(session, udid)
time.sleep(3)
LogManager.method_info(f"重启tiktok", "关注打招呼", udid)
# 设置查找深度
session.appium_settings({"snapshotMaxDepth": 15})
@@ -317,6 +317,8 @@ class ScriptManager():
# 返回上一步
def goBack(count):
for i in range(count):
LogManager.method_info(f"返回上一步", "关注打招呼", udid)
session.appium_settings({"snapshotMaxDepth": 15})
ControlUtils.clickBack(session)
time.sleep(2)
@@ -338,9 +340,13 @@ class ScriptManager():
aid = anchor["anchorId"]
anchorCountry = anchor.get("country", "")
LogManager.method_info(f"主播的数据,用户名:{aid},国家:{anchorCountry}", "关注打招呼", udid)
# 点击搜索按钮
ControlUtils.clickSearch(session)
LogManager.method_info(f"点击搜索按钮", "关注打招呼", udid)
# 强制刷新session
session.appium_settings({"snapshotMaxDepth": 15})
@@ -365,21 +371,22 @@ class ScriptManager():
session.appium_settings({"snapshotMaxDepth": 23})
try:
# 点击关注按钮
# 点击进入首页
ControlUtils.clickFollow(session, aid)
LogManager.method_info("点击进入主播首页", "关注打招呼", udid)
except wda.WDAElementNotFoundError:
# 如果没有“关注”按钮,则不点击
print("未找到‘关注’按钮,跳过点击。")
LogManager.method_info("未找到‘关注’按钮,跳过点击。", "关注打招呼", udid)
LogManager.method_info("未找到进入主播首页的按钮,跳过点击。", "关注打招呼", udid)
goBack(2)
session.appium_settings({"snapshotMaxDepth": 15})
continue
time.sleep(2)
# 找到并点击第一个视频
cellClickResult, workCount = ControlUtils.clickFirstVideoFromDetailPage(session)
LogManager.method_info(f"点击第一个视频", "关注打招呼", udid)
time.sleep(2)
# 观看主播视频
@@ -465,8 +472,8 @@ class ScriptManager():
LogManager.method_info(f"传递的打招呼的数据:{ev.prologueList}", "关注打招呼", udid)
# 准备打招呼的文案
# text = random.choice(ev.prologueList)
text = 'hello'
text = random.choice(ev.prologueList)
# text = 'hello'
LogManager.method_info(f"取出打招呼的数据,{text}, 判断是否需要翻译", "关注打招呼", udid)
@@ -474,9 +481,10 @@ class ScriptManager():
if isContainChniese:
# 翻译成主播国家的语言
LogManager.method_info(f"需要翻译:{text}, 即将进行翻译", "关注打招呼", udid)
LogManager.method_info(f"需要翻译:{text},参数为:国家为{anchorCountry}, 即将进行翻译", "关注打招呼", udid)
msg = Requester.translation(text, anchorCountry)
LogManager.method_info(f"翻译成功:{msg}, ", "关注打招呼", udid)
else:
@@ -502,16 +510,16 @@ class ScriptManager():
goBack(1)
# 点击关注按钮
followButton = AiUtils.getFollowButton(session)
if followButton is not None:
LogManager.method_info("找到关注按钮了", "关注打招呼", udid)
followButton.click()
else:
LogManager.method_info("没找到关注按钮", "关注打招呼", udid)
time.sleep(1)
goBack(4)
session.appium_settings({"snapshotMaxDepth": 15})
continue
# followButton = AiUtils.getFollowButton(session)
# if followButton is not None:
# LogManager.method_info("找到关注按钮了", "关注打招呼", udid)
# followButton.click()
# else:
# LogManager.method_info("没找到关注按钮", "关注打招呼", udid)
# time.sleep(1)
# goBack(4)
# session.appium_settings({"snapshotMaxDepth": 15})
# continue
session.appium_settings({"snapshotMaxDepth": 15})
goBack(3)
@@ -718,26 +726,27 @@ class ScriptManager():
last_msg = next((item['text'] for item in reversed(msgs) if item['type'] == 'msg'),
random.choice(text_list))
LogManager.method_info(f"检测到对方最后发送的消息:{last_msg}", "检测消息", udid)
isLanguage = AiUtils.is_language(last_msg)
if isLanguage:
# LogManager.method_info(f"{last_msg}", "检测消息", udid)
last_msg_text = last_msg
else:
LogManager.method_info(f"对方发送的消息不是语言,随机挑选作为最后一条进行回复:{last_msg}", "检测消息", udid)
last_msg_text = random.choice(text_list)
# 111111
if AiUtils.contains_chinese(last_msg_text):
LogManager.method_info(f"需要翻译:{last_msg_text}, 即将进行翻译", "检测消息", udid)
last_msg_text = Requester.translation(last_msg_text)
LogManager.method_info(f"翻译成功:{last_msg_text}, ", "检测消息", udid)
# 向ai发送信息
# 获取主播的名称
anchor_name = AiUtils.get_navbar_anchor_name(session)
LogManager.method_info(f"获取主播的名称:{anchor_name}", "检测消息", udid)
LogManager.method_info(f"获取主播最后发送的消息 进行翻译:{last_msg}", "检测消息", udid)
last_msg = Requester.translation(last_msg, "中国")
LogManager.method_info(f"翻译后的内容:{last_msg}", "检测消息", udid)
@@ -751,31 +760,28 @@ class ScriptManager():
}]
print(last_data)
LogManager.method_info(f"主播最后发送的数据:{last_data}", "检测消息", udid)
LogManager.method_info(f"主播最后发送的数据,传递给前端进行记录:{last_data}", "检测消息", udid)
JsonUtils.append_json_items(last_data, "log/last_message.json")
sel = session.xpath("//TextView")
sel = session.xpath("//TextView")
if anchor_name not in anchorWithSession:
# 如果是第一次发消息(没有sessionId的情况)
LogManager.method_info(f"第一次发消息:{anchor_name},没有记忆", "检测消息", udid)
aiResult, sessionId = Requester.chatToAi({"query": last_msg_text, "user": "1"})
# aiResult = response['result']
# sessionId = response['session_id']
anchorWithSession[anchor_name] = sessionId
# 找到输入框输入ai返回出来的消息
# 123456
if sel.exists:
sel.click() # 聚焦
time.sleep(1)
sel.clear_text()
sel.set_text(f"{aiResult or '暂无数据'}\n")
else:
LogManager.method_error("找不到输入框,重启", "检测消息", udid)
raise Exception("找不到输入框,重启")
else:
LogManager.method_info(f"不是一次发消息:{anchor_name},有记忆", "检测消息", udid)
# 如果不是第一次发消息证明存储的有sessionId
sessionId = anchorWithSession[anchor_name]