refactor(fudai): 抽 run_once_basic 中"IN_LIVE_ROOM"分支到 handle_in_live_room_stage
将"在直播间"阶段的处理逻辑(约 44 行)抽到 fudai_detail_helpers.handle_in_live_room_stage。逻辑: - 如果刚切换直播间(_just_switched_room=True),等待福袋加载 (switch_room_wait_after_stage_diag_seconds 秒) - 调用 _handle_live_room_has_or_not_fudai 寻找福袋图标 - 写完成日志 douyin_fudai.py: 3071 → 3042 行 (-29) fudai_detail_helpers.py: 572 → 618 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b5d7943af0
commit
c9a07cc91e
2 files changed
+50
-33
No files matched your search
@@ -1707,40 +1707,11 @@ class fudai_analyse:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 在直播间:如果刚刚切换了直播间,等待福袋加载
|
||||
just_switched = getattr(self, "_just_switched_room", False)
|
||||
if just_switched:
|
||||
try:
|
||||
self._just_switched_room = False # 清除标志
|
||||
wait_seconds = float(
|
||||
getattr(self, "switch_room_wait_after_stage_diag_seconds", 7.0)
|
||||
or 7.0
|
||||
)
|
||||
if wait_seconds > 0:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"切换直播间后,阶段检测完成,等待福袋加载",
|
||||
wait_seconds=wait_seconds,
|
||||
)
|
||||
self.operation.delay(wait_seconds)
|
||||
except Exception as e:
|
||||
try:
|
||||
self._just_switched_room = False # 确保清除标志
|
||||
self._log_kv("流程", "等待福袋加载时出错", error=str(e))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 在直播间:寻找福袋图标并尝试点开
|
||||
fudai_search_start = time.time()
|
||||
self._handle_live_room_has_or_not_fudai()
|
||||
fudai_search_elapsed = time.time() - fudai_search_start
|
||||
self._log_kv("福袋查找", f"福袋查找完成,耗时: {fudai_search_elapsed:.3f}s")
|
||||
elapsed = time.time() - start_time
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"run_once_basic完成(处理直播间)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
handle_in_live_room_stage,
|
||||
)
|
||||
|
||||
handle_in_live_room_stage(self, start_time)
|
||||
elif stage in ("RECOMMEND_PAGE", "FOLLOW_LIST", "LIVE_LIST"):
|
||||
# 处理推荐/关注/直播列表页:回到直播间或切换
|
||||
if stage == "RECOMMEND_PAGE":
|
||||
|
||||
@@ -42,6 +42,52 @@ def log_screenshot_failed(
|
||||
pass
|
||||
|
||||
|
||||
def handle_in_live_room_stage(analyser, start_time: float) -> None:
|
||||
"""run_once_basic stage in ("IN_LIVE_ROOM", "LIVE_OR_UNKNOWN") 分支:
|
||||
|
||||
- 如果刚切换直播间(_just_switched_room=True),等待福袋加载
|
||||
(switch_room_wait_after_stage_diag_seconds 秒)
|
||||
- 调用 _handle_live_room_has_or_not_fudai 寻找福袋图标
|
||||
- 写完成日志
|
||||
"""
|
||||
# 如果刚刚切换了直播间,等待福袋加载
|
||||
just_switched = getattr(analyser, "_just_switched_room", False)
|
||||
if just_switched:
|
||||
try:
|
||||
analyser._just_switched_room = False
|
||||
wait_seconds = float(
|
||||
getattr(analyser, "switch_room_wait_after_stage_diag_seconds", 7.0)
|
||||
or 7.0
|
||||
)
|
||||
if wait_seconds > 0:
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"切换直播间后,阶段检测完成,等待福袋加载",
|
||||
wait_seconds=wait_seconds,
|
||||
)
|
||||
analyser.operation.delay(wait_seconds)
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._just_switched_room = False
|
||||
analyser._log_kv("流程", "等待福袋加载时出错", error=str(e))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 在直播间:寻找福袋图标并尝试点开
|
||||
fudai_search_start = time.time()
|
||||
analyser._handle_live_room_has_or_not_fudai()
|
||||
fudai_search_elapsed = time.time() - fudai_search_start
|
||||
analyser._log_kv(
|
||||
"福袋查找", f"福袋查找完成,耗时: {fudai_search_elapsed:.3f}s"
|
||||
)
|
||||
elapsed = time.time() - start_time
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"run_once_basic完成(处理直播间)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
)
|
||||
|
||||
|
||||
def handle_lottery_result_stage(analyser, start_time: float) -> None:
|
||||
"""run_once_basic stage == "FUDai_RESULT" 分支:
|
||||
|
||||
|
||||
Reference in new issue
Block a user