From 887f8bad3e06eb62e88caaf92720f52a6f3f098c Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 12:05:29 +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=AD=9B=E9=80=89=E4=B8=8D?= =?UTF-8?q?=E9=80=9A=E8=BF=87"=E5=9D=97=E5=88=B0=20handle=5Ffilter=5Fskip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将筛选不通过分支(约 50 行)抽到 helper: - 写"筛选不通过"日志 - 关闭详情页 - 按 needswitch 切换直播间 - clear_task_count_flag - 写完成日志 douyin_fudai.py: 1962 → 1921 行 (-41) fudai_detail_helpers.py: 1876 → 1930 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 49 ++--------------- .../fudai_modules/fudai_detail_helpers.py | 54 +++++++++++++++++++ 2 files changed, 58 insertions(+), 45 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index f19a1f5..4f99a52 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1521,52 +1521,11 @@ class fudai_analyse: # 如果不是高价值福袋,或者不是倒计时原因,筛选不通过,直接跳过 if skip: - try: - self._log_kv( - "流程", - "_handle_in_fudai_detail:第一次打开时筛选不通过,直接跳过", - skip_reason=skip_reason, - ) - except Exception: - pass - # 关闭详情页 - try: - douyin_fudai_detail.close_fudai_detail(self) - except Exception: - pass - - # 如果允许切换直播间,筛选不通过直接切换直播间 - try: - needswitch = bool(getattr(self, "needswitch", True)) - except Exception: - needswitch = True - if needswitch: - try: - self._log_kv( - "流程", - "_handle_in_fudai_detail:筛选不通过后切换直播间", - skip_reason=skip_reason, - ) - except Exception: - pass - try: - from douyin.core.fudai_modules.fudai_detail_helpers import ( - fallback_swipe_up_to_next_live, - ) - - fallback_swipe_up_to_next_live(self) - except Exception: - pass - - # 清除任务数量标志 - clear_task_count_flag(self) - - elapsed = time.time() - start_time - self._log_kv( - "流程", - "_handle_in_fudai_detail完成(筛选不通过)", - elapsed_seconds=round(elapsed, 2), + from douyin.core.fudai_modules.fudai_detail_helpers import ( + handle_filter_skip, ) + + handle_filter_skip(self, skip_reason, start_time) return except Exception as e: # 筛选检查异常,记录日志但继续流程 diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index fbe2137..96fe18c 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,60 @@ def log_screenshot_failed( pass +def handle_filter_skip(analyser, skip_reason: str, start_time: float) -> None: + """_handle_in_fudai_detail 筛选不通过分支:关闭详情 + 按 needswitch 切换直播间。 + + 流程: + 1. 写"第一次打开时筛选不通过"日志 + 2. 关闭详情页 + 3. 如果 needswitch=True:写日志 + fallback_swipe_up_to_next_live + 4. clear_task_count_flag + 5. 写完成日志(调用方 return) + """ + from douyin.fudai import douyin_fudai_detail + + try: + analyser._log_kv( + "流程", + "_handle_in_fudai_detail:第一次打开时筛选不通过,直接跳过", + skip_reason=skip_reason, + ) + except Exception: + pass + try: + douyin_fudai_detail.close_fudai_detail(analyser) + except Exception: + pass + + try: + needswitch = bool(getattr(analyser, "needswitch", True)) + except Exception: + needswitch = True + + if needswitch: + try: + analyser._log_kv( + "流程", + "_handle_in_fudai_detail:筛选不通过后切换直播间", + skip_reason=skip_reason, + ) + except Exception: + pass + try: + fallback_swipe_up_to_next_live(analyser) + except Exception: + pass + + clear_task_count_flag(analyser) + + elapsed = time.time() - start_time + analyser._log_kv( + "流程", + "_handle_in_fudai_detail完成(筛选不通过)", + elapsed_seconds=round(elapsed, 2), + ) + + def handle_high_value_record_reservation( analyser, detail,