临时提交
This commit is contained in:
@@ -7,6 +7,7 @@ import wda
|
||||
import os
|
||||
from Utils.AiUtils import AiUtils
|
||||
from Utils.ControlUtils import ControlUtils
|
||||
from Utils.IOSAIStorage import IOSAIStorage
|
||||
from Utils.JsonUtils import JsonUtils
|
||||
from Utils.LogManager import LogManager
|
||||
from Entity.Variables import anchorList, removeModelFromAnchorList, anchorWithSession
|
||||
@@ -105,7 +106,13 @@ class ScriptManager():
|
||||
if homeButton:
|
||||
LogManager.method_info("有首页按钮,查看视频", "养号", udid)
|
||||
videoTime = random.randint(5, 15)
|
||||
event.wait(timeout=videoTime)
|
||||
LogManager.method_info("准备停止脚本", method="task")
|
||||
for _ in range(videoTime): # 0.2 秒一片
|
||||
if event.is_set():
|
||||
LogManager.method_info("停止脚本中", method="task")
|
||||
break
|
||||
event.wait(timeout=1)
|
||||
LogManager.method_info("停止脚本成功", method="task")
|
||||
|
||||
# 重置 session
|
||||
client = wda.USBClient(udid)
|
||||
@@ -118,7 +125,10 @@ class ScriptManager():
|
||||
|
||||
LogManager.method_info("继续观看视频", "养号", udid)
|
||||
videoTime = random.randint(10, 30)
|
||||
event.wait(timeout=videoTime)
|
||||
for _ in range(videoTime):
|
||||
if event.is_set():
|
||||
break
|
||||
event.wait(timeout=1)
|
||||
|
||||
LogManager.method_info("准备划到下一个视频", "养号", udid)
|
||||
client.swipe_up()
|
||||
@@ -126,7 +136,10 @@ class ScriptManager():
|
||||
LogManager.method_error("找不到首页按钮。出错了", "养号", udid)
|
||||
else:
|
||||
nextTime = random.randint(1, 5)
|
||||
event.wait(timeout=nextTime)
|
||||
for _ in range(nextTime):
|
||||
if event.is_set():
|
||||
break
|
||||
event.wait(timeout=1)
|
||||
client.swipe_up()
|
||||
|
||||
except Exception as e:
|
||||
@@ -168,7 +181,10 @@ class ScriptManager():
|
||||
# 抛出异常
|
||||
raise Exception(f"找不到直播按钮,抛出异常 重新启动")
|
||||
waitTime = random.randint(15, 20)
|
||||
event.wait(timeout=waitTime)
|
||||
for _ in range(waitTime): # 0.2 秒一片
|
||||
if event.is_set():
|
||||
break
|
||||
event.wait(timeout=1)
|
||||
|
||||
live_button = session(xpath='//XCUIElementTypeButton[@name="直播"]')
|
||||
if live_button.exists:
|
||||
@@ -239,8 +255,12 @@ class ScriptManager():
|
||||
|
||||
print("--------------------------------------------")
|
||||
# 换成
|
||||
if not self.interruptible_sleep(event, random.randint(300, 600)):
|
||||
break
|
||||
total_seconds = random.randint(300, 600)
|
||||
for _ in range(total_seconds): # 0.2 秒一片
|
||||
if event.is_set():
|
||||
break
|
||||
event.wait(timeout=1)
|
||||
|
||||
session.swipe_up()
|
||||
|
||||
# 正常退出(外部 event 触发)
|
||||
@@ -256,7 +276,10 @@ class ScriptManager():
|
||||
except Exception:
|
||||
pass
|
||||
# 冷却后整段流程重来
|
||||
event.wait(timeout=backoff_sec)
|
||||
for _ in range(backoff_sec): # 0.2 秒一片
|
||||
if event.is_set():
|
||||
break
|
||||
event.wait(timeout=1)
|
||||
continue
|
||||
|
||||
"""
|
||||
@@ -275,6 +298,10 @@ class ScriptManager():
|
||||
retries += 1
|
||||
LogManager.method_error(f"greetNewFollowers 出现异常: {e},准备第 {retries} 次重试", "关注打招呼", udid)
|
||||
event.wait(timeout=3)
|
||||
|
||||
if event.is_set():
|
||||
LogManager.method_info("外层 while 检测到停止,即将 break", "关注打招呼", udid)
|
||||
break
|
||||
LogManager.method_error("greetNewFollowers 重试次数耗尽,任务终止", "关注打招呼", udid)
|
||||
|
||||
# 关注打招呼以及回复主播消息
|
||||
@@ -317,6 +344,10 @@ class ScriptManager():
|
||||
# 循环条件。1、 循环关闭 2、 数据处理完毕
|
||||
while not event.is_set():
|
||||
|
||||
LogManager.method_info("=== 外层 while 新一轮 ===", "关注打招呼", udid)
|
||||
if event.is_set():
|
||||
break
|
||||
|
||||
# 获取一个主播,
|
||||
LogManager.method_info(f"开始获取数据", "关注打招呼", udid)
|
||||
# 获取一个主播,
|
||||
@@ -404,7 +435,13 @@ class ScriptManager():
|
||||
count = workCount
|
||||
|
||||
while count != 0:
|
||||
event.wait(timeout=5)
|
||||
LogManager.method_info("准备停止脚本", method="task")
|
||||
for _ in range(5):
|
||||
LogManager.method_info("停止脚本中", method="task")
|
||||
if event.is_set():
|
||||
break
|
||||
event.wait(timeout=1)
|
||||
LogManager.method_info("停止脚本成功", method="task")
|
||||
img = client.screenshot()
|
||||
event.wait(timeout=1)
|
||||
|
||||
@@ -427,14 +464,22 @@ class ScriptManager():
|
||||
# if r == True:
|
||||
|
||||
count -= 1
|
||||
|
||||
LogManager.method_info("准备停止脚本", method="task")
|
||||
# 随机看视频 15~30秒
|
||||
event.wait(timeout=random.randint(15, 30))
|
||||
for _ in range(random.randint(15, 30)):
|
||||
LogManager.method_info("停止脚本中", method="task")
|
||||
if event.is_set():
|
||||
break
|
||||
event.wait(timeout=1)
|
||||
LogManager.method_info("停止脚本成功", method="task")
|
||||
if count != 0:
|
||||
client.swipe_up()
|
||||
|
||||
# 右滑返回
|
||||
client.swipe_right()
|
||||
if event.is_set():
|
||||
LogManager.method_info("viewAnchorVideo 检测到停止,提前退出", "关注打招呼", udid)
|
||||
return
|
||||
|
||||
# 如果打开视频失败。说明该主播没有视频
|
||||
if cellClickResult == True:
|
||||
@@ -510,7 +555,6 @@ class ScriptManager():
|
||||
LogManager.method_info(f"给主播{aid} 发送消息失败", "关注打招呼", udid)
|
||||
|
||||
# 接着下一个主播
|
||||
# removeModelFromAnchorList(anchor)
|
||||
goBack(1)
|
||||
|
||||
# 点击关注按钮
|
||||
@@ -687,13 +731,6 @@ class ScriptManager():
|
||||
)
|
||||
|
||||
# 用户消息
|
||||
# xp_badge_numeric = (
|
||||
# '//XCUIElementTypeOther['
|
||||
# ' @name="AWEIMChatListCellUnreadCountViewComponent"'
|
||||
# ' or @name="TikTokIMImpl.InboxCellUnreadCountViewBuilder"'
|
||||
# ']//XCUIElementTypeStaticText[@value and translate(@value,"0123456789","")=""]'
|
||||
# )
|
||||
|
||||
xp_badge_numeric = (
|
||||
"("
|
||||
# 你的两类未读容器组件 + 数字徽标(value 纯数字)
|
||||
@@ -725,15 +762,14 @@ class ScriptManager():
|
||||
if user_text:
|
||||
user_text.tap()
|
||||
event.wait(timeout=3)
|
||||
|
||||
xml = session.source()
|
||||
msgs = AiUtils.extract_messages_from_xml(xml)
|
||||
# 检测出对方发的最后一条信息
|
||||
# last_msg_text = next(item['text'] for item in reversed(msgs) if item['type'] == 'msg')
|
||||
|
||||
text_list = ['What do you think of my live stream?',
|
||||
'What do you think makes my streams special?',
|
||||
'Do you think I’m one of the most engaging streamers you’ve seen?']
|
||||
|
||||
# 检测出对方发的最后一条信息
|
||||
last_msg = next((item['text'] for item in reversed(msgs) if item['type'] == 'msg'),
|
||||
random.choice(text_list))
|
||||
|
||||
@@ -775,13 +811,17 @@ class ScriptManager():
|
||||
LogManager.method_info(f"主播最后发送的数据,传递给前端进行记录:{last_data}", "检测消息", udid)
|
||||
JsonUtils.append_json_items(last_data, "log/last_message.json")
|
||||
|
||||
# 从C盘中读取数据
|
||||
anchorWithSession = IOSAIStorage.load()
|
||||
|
||||
sel = session.xpath("//TextView")
|
||||
if anchor_name not in anchorWithSession:
|
||||
# 如果是第一次发消息(没有sessionId的情况)
|
||||
LogManager.method_info(f"第一次发消息:{anchor_name},没有记忆", "检测消息", udid)
|
||||
|
||||
LogManager.method_info(f"第一次发消息:{anchor_name},没有记忆 开始请求ai", "检测消息", udid)
|
||||
LogManager.method_info(f"向ai发送的参数", "检测消息", udid)
|
||||
aiResult, sessionId = Requester.chatToAi({"query": last_msg_text, "user": "1"})
|
||||
anchorWithSession[anchor_name] = sessionId
|
||||
IOSAIStorage.save({anchor_name: sessionId})
|
||||
|
||||
# 找到输入框,输入ai返回出来的消息
|
||||
|
||||
if sel.exists:
|
||||
@@ -913,4 +953,5 @@ class ScriptManager():
|
||||
timeout = min(slice_, left)
|
||||
event.wait(timeout=timeout)
|
||||
left -= timeout
|
||||
return not event.is_set() # 返回 True 表示正常睡完,False 被中断
|
||||
return not event.is_set() # 返回 True 表示正常睡完,False 被中断
|
||||
|
||||
|
||||
Reference in New Issue
Block a user