From 3de07d7a668f98b1886737739b6aec1e165177f0 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 11:51:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20=5Fhandle=5Fin?= =?UTF-8?q?=5Ffudai=5Fdetail=20=E4=B8=AD"=E7=AE=80=E5=8D=95=E8=B7=B3?= =?UTF-8?q?=E8=BF=87=E7=8A=B6=E6=80=81"=E7=9A=84=203=20=E4=B8=AA=E5=88=86?= =?UTF-8?q?=E6=94=AF=E5=88=B0=20handle=5Fsimple=5Fskip=5Fstatus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- douyin/core/douyin_fudai.py | 69 +++++++------------ .../fudai_modules/fudai_detail_helpers.py | 27 ++++++++ 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 539ca5e..7ac87ec 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -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": diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index c9101d4..e5373a8 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -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 不可用时使用。