新增搜索主播id锁,防止多台手机重复获取同一个id

This commit is contained in:
2025-11-04 20:44:23 +08:00
parent 81761a576b
commit 6337c951fb
2 changed files with 39 additions and 35 deletions

View File

@@ -667,7 +667,6 @@ def delete_last_message():
def stopAllTask(): def stopAllTask():
idList = request.get_json() idList = request.get_json()
code, msg = ThreadManager.batch_stop(idList) code, msg = ThreadManager.batch_stop(idList)
time.sleep(2)
return ResultData(code, [], msg).toJson() return ResultData(code, [], msg).toJson()
# 切换账号 # 切换账号

View File

@@ -39,6 +39,8 @@ class ScriptManager():
# 初始化获取模版所在的地址 # 初始化获取模版所在的地址
current_dir = Path(__file__).resolve().parent current_dir = Path(__file__).resolve().parent
# 项目根目录(假设你的类文件在项目的子目录里,比如 Module/OCR/OCRUtils.py # 项目根目录(假设你的类文件在项目的子目录里,比如 Module/OCR/OCRUtils.py
self.lock = threading.Lock()
project_root = current_dir.parent # 如果你确定这个文件就在项目根目录下,可省略这行 project_root = current_dir.parent # 如果你确定这个文件就在项目根目录下,可省略这行
# resources 文件夹路径 # resources 文件夹路径
@@ -221,9 +223,15 @@ class ScriptManager():
LogManager.method_error("找不到首页按钮。出错了", "养号", udid) LogManager.method_error("找不到首页按钮。出错了", "养号", udid)
if isComment and random.random() > 0.70: if isComment and random.random() > 0.70:
print("点击进行评论")
self.comment_flow(filePath, session, udid, recomend_cx, recomend_cy) self.comment_flow(filePath, session, udid, recomend_cx, recomend_cy)
event.wait(timeout=2) event.wait(timeout=2)
print("123456", session.source())
home = AiUtils.findHomeButton(session)
if not home:
raise Exception("没有找到首页按钮,重置")
videoTime = random.randint(15, 30) videoTime = random.randint(15, 30)
for _ in range(videoTime): for _ in range(videoTime):
if event.is_set(): if event.is_set():
@@ -470,9 +478,10 @@ class ScriptManager():
LogManager.method_info("=== 外层 while 新一轮 ===", "关注打招呼", udid) LogManager.method_info("=== 外层 while 新一轮 ===", "关注打招呼", udid)
if event.is_set(): if event.is_set():
break break
with self.lock:
# 获取一个主播, # 获取一个主播,
LogManager.method_info(f"开始获取数据", "关注打招呼", udid) LogManager.method_info(f"开始获取数据", "关注打招呼", udid)
# 获取一个主播, # 获取一个主播,
result = AiUtils.peek_aclist_first() result = AiUtils.peek_aclist_first()
LogManager.method_info(f"数据是:{result}", "关注打招呼", udid) LogManager.method_info(f"数据是:{result}", "关注打招呼", udid)
@@ -530,7 +539,6 @@ class ScriptManager():
LogManager.method_info(f"输入主播id:{aid or '暂无数据'}", "关注打招呼", udid) LogManager.method_info(f"输入主播id:{aid or '暂无数据'}", "关注打招呼", udid)
input.set_text(f"{aid or '暂无数据'}\n") input.set_text(f"{aid or '暂无数据'}\n")
# 定位 "关注" 按钮 通过关注按钮的位置点击主播首页 # 定位 "关注" 按钮 通过关注按钮的位置点击主播首页
session.appium_settings({"snapshotMaxDepth": 25}) session.appium_settings({"snapshotMaxDepth": 25})
@@ -613,8 +621,6 @@ class ScriptManager():
event.wait(timeout=1) event.wait(timeout=1)
LogManager.method_info("停止脚本成功", method="task") LogManager.method_info("停止脚本成功", method="task")
# 使用OCR进行评论 # 使用OCR进行评论
if isComment: if isComment:
self.comment_flow(filePath, session, udid, 100, 100) self.comment_flow(filePath, session, udid, 100, 100)
@@ -659,8 +665,6 @@ class ScriptManager():
msgButton = AiUtils.getSendMesageButton(session) msgButton = AiUtils.getSendMesageButton(session)
event.wait(timeout=2) event.wait(timeout=2)
if msgButton.exists: if msgButton.exists:
# 进入聊天页面 # 进入聊天页面
msgButton.click() msgButton.click()
@@ -869,6 +873,7 @@ class ScriptManager():
if event.is_set(): if event.is_set():
break break
with self.lock:
# 获取一个主播, # 获取一个主播,
LogManager.method_info(f"开始获取数据", "关注打招呼(联盟号)", udid) LogManager.method_info(f"开始获取数据", "关注打招呼(联盟号)", udid)
# 获取一个主播, # 获取一个主播,