refactor(fudai): 抽 run_once_basic 中"刚记录预约后切换直播间"块到 try_just_recorded_reservation_switch

将 run_once_basic 步骤"检查是否刚刚记录了预约,如果是则强制切换直播间"
独立块(约 47 行)抽到 fudai_detail_helpers.try_just_recorded_reservation_switch。

返回值约定:
- True:刚记录预约,已尝试切换并写完成日志(调用方应直接 return)
- False:未触发,调用方继续正常流程

douyin_fudai.py: 3022 → 2983 行 (-39)
fudai_detail_helpers.py: 657 → 716 行

douyin_fudai.py 跌破 3000 行(4121 → 2983,本会话累计削减 1138 行)

验证:
- pytest 1013 passed
- compile OK

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
CodexandClaude Opus 4.7 committed 2026-05-22 11:16:38 +08:00
1 parent 7307b2abb5
commit 849160304e
2 files changed
+65 -45

No files matched your search

+6 -45
View File
@@ -1483,51 +1483,12 @@ class fudai_analyse:
pass
# 检查是否刚刚记录了预约,如果是,强制切换直播间,避免在同一直播间循环
try:
just_recorded = getattr(self, "_just_recorded_reservation", False)
if just_recorded:
self._just_recorded_reservation = False # 清除标志
try:
self._log_kv(
"预约",
"[预约] 刚刚记录预约,继续在新直播间搜索福袋",
)
except Exception:
pass
try:
needswitch_cfg = bool(getattr(self, "needswitch", True))
except Exception:
needswitch_cfg = True
if needswitch_cfg:
try:
self.swipe_up_to_next_live()
except Exception as exc:
try:
self._log_kv(
"预约",
"[预约] 执行上滑切换失败",
error=str(exc),
error_type=type(exc).__name__,
)
except Exception:
pass
else:
try:
self._log_kv(
"预约",
"[预约] just_recorded_reservation 触发,但 needswitch=False,未切换",
)
except Exception:
pass
elapsed = time.time() - start_time
self._log_kv(
"流程",
"run_once_basic完成(记录预约后切换直播间)",
elapsed_seconds=round(elapsed, 2),
)
return
except Exception:
pass
from douyin.core.fudai_modules.fudai_detail_helpers import (
try_just_recorded_reservation_switch,
)
if try_just_recorded_reservation_switch(self, start_time):
return
# 预约检查耗时记录
reservation_elapsed = time.time() - reservation_check_start
@@ -42,6 +42,65 @@ def log_screenshot_failed(
pass
def try_just_recorded_reservation_switch(analyser, start_time: float) -> bool:
"""run_once_basic 步骤:检查是否刚刚记录了预约,如果是则强制切换直播间。
返回:
True:刚记录预约,已尝试切换并写完成日志(调用方应直接 return)
False:未触发,调用方继续正常流程
"""
try:
just_recorded = getattr(analyser, "_just_recorded_reservation", False)
if not just_recorded:
return False
analyser._just_recorded_reservation = False # 清除标志
try:
analyser._log_kv(
"预约",
"[预约] 刚刚记录预约,继续在新直播间搜索福袋",
)
except Exception:
pass
try:
needswitch_cfg = bool(getattr(analyser, "needswitch", True))
except Exception:
needswitch_cfg = True
if needswitch_cfg:
try:
analyser.swipe_up_to_next_live()
except Exception as exc:
try:
analyser._log_kv(
"预约",
"[预约] 执行上滑切换失败",
error=str(exc),
error_type=type(exc).__name__,
)
except Exception:
pass
else:
try:
analyser._log_kv(
"预约",
"[预约] just_recorded_reservation 触发,但 needswitch=False,未切换",
)
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv(
"流程",
"run_once_basic完成(记录预约后切换直播间)",
elapsed_seconds=round(elapsed, 2),
)
return True
except Exception:
return False
def handle_coupon_popup(analyser, start_time: float) -> None:
"""run_once_basic stage == "COUPON_POPUP" 分支:按返回键关闭优惠券弹窗。"""
analyser._log_kv("弹窗处理", "检测到优惠券弹窗,按返回键关闭")