新增搜索主播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():
idList = request.get_json()
code, msg = ThreadManager.batch_stop(idList)
time.sleep(2)
return ResultData(code, [], msg).toJson()
# 切换账号

View File

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