refactor(fudai): 抽 _handle_in_fudai_detail 中"简单跳过状态"的 3 个分支到 handle_simple_skip_status
last_status == "coupon_popup" / "watch_task" / "validation_failed" 三个分支 结构完全相同(写日志 → clear_task_count_flag → 写完成日志 → return), 统一抽到 handle_simple_skip_status 通用模板。 douyin_fudai.py: 2281 → 2260 行 (-21) fudai_detail_helpers.py: 1468 → 1495 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d35fadde54
commit
3de07d7a66
2 files changed
+51
-45
No files matched your search
+24
-45
@@ -1672,60 +1672,39 @@ class fudai_analyse:
|
||||
try:
|
||||
last_status = getattr(self, "_last_fudai_detail_status", "")
|
||||
if last_status == "coupon_popup":
|
||||
try:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:检测到优惠券弹窗,已关闭,跳过后续处理",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
handle_simple_skip_status,
|
||||
)
|
||||
|
||||
# 清除任务数量标志
|
||||
clear_task_count_flag(self)
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail完成(优惠券弹窗)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
handle_simple_skip_status(
|
||||
self,
|
||||
start_time,
|
||||
"_handle_in_fudai_detail:检测到优惠券弹窗,已关闭,跳过后续处理",
|
||||
"优惠券弹窗",
|
||||
)
|
||||
return
|
||||
elif last_status == "watch_task":
|
||||
try:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:检测到'观看X分钟'任务,已在OCR阶段跳过,无需后续处理",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
handle_simple_skip_status,
|
||||
)
|
||||
|
||||
# 清除任务数量标志
|
||||
clear_task_count_flag(self)
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail完成(观看任务)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
handle_simple_skip_status(
|
||||
self,
|
||||
start_time,
|
||||
"_handle_in_fudai_detail:检测到'观看X分钟'任务,已在OCR阶段跳过,无需后续处理",
|
||||
"观看任务",
|
||||
)
|
||||
return
|
||||
elif last_status == "validation_failed":
|
||||
try:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:福袋详情数据验证失败,识别出错,跳过后续处理",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
handle_simple_skip_status,
|
||||
)
|
||||
|
||||
# 清除任务数量标志
|
||||
clear_task_count_flag(self)
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail完成(验证失败)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
handle_simple_skip_status(
|
||||
self,
|
||||
start_time,
|
||||
"_handle_in_fudai_detail:福袋详情数据验证失败,识别出错,跳过后续处理",
|
||||
"验证失败",
|
||||
)
|
||||
return
|
||||
elif last_status == "error":
|
||||
|
||||
@@ -42,6 +42,33 @@ def log_screenshot_failed(
|
||||
pass
|
||||
|
||||
|
||||
def handle_simple_skip_status(
|
||||
analyser, start_time: float, log_message: str, completion_label: str
|
||||
) -> None:
|
||||
"""_handle_in_fudai_detail 中"简单跳过"分支的通用模板。
|
||||
|
||||
用于 last_status 命中如下特定状态后的早返回:
|
||||
- coupon_popup(优惠券弹窗)
|
||||
- watch_task(观看任务)
|
||||
- validation_failed(验证失败)
|
||||
|
||||
流程:写中间日志 → clear_task_count_flag → 写完成日志 → 调用方 return。
|
||||
"""
|
||||
try:
|
||||
analyser._log_kv("流程", log_message)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
clear_task_count_flag(analyser)
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
f"_handle_in_fudai_detail完成({completion_label})",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
)
|
||||
|
||||
|
||||
def fallback_swipe_up_to_next_live(analyser) -> None:
|
||||
"""兜底版上滑切换直播间:当 swipe_up_to_next_live 不可用时使用。
|
||||
|
||||
|
||||
Reference in new issue
Block a user