From b8ccb899c0951cf22d7a5cbec92fca69d9c95a92 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 12:09:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20=5Fhandle=5Fin?= =?UTF-8?q?=5Ffudai=5Fdetail=20=E6=AD=A5=E9=AA=A41"=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E8=AF=A6=E6=83=85=E5=85=9C=E5=BA=95"?= =?UTF-8?q?=E5=9D=97=E5=88=B0=20reread=5Ffudai=5Fdetail=5Ffallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将"未找到保存的详情数据时的兜底重读"逻辑(约 22 行)抽到 helper: - 写说明日志 - 调用 read_fudai_detail_with_retries 重新读取 - 成功则更新 _last_fudai_detail_tuple 和 _current_fudai_content - 返回 detail(成功)或 None(失败) douyin_fudai.py: 1821 → 1804 行 (-17) fudai_detail_helpers.py: 2047 → 2083 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 25 +++---------- .../fudai_modules/fudai_detail_helpers.py | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index b0d08c6..6983070 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1244,28 +1244,11 @@ class fudai_analyse: detail = getattr(self, "_last_fudai_detail_tuple", None) if detail is None or not isinstance(detail, tuple) or len(detail) < 6: # 如果没有保存的详情数据,需要重新读取(兜底逻辑) - try: - self._log_kv( - "流程", - "_handle_in_fudai_detail:未找到第一次读取的详情数据,重新读取", - ) - except Exception: - pass - detail = douyin_fudai_detail.read_fudai_detail_with_retries( - self, - fudai_x=0, - read_once_callback=douyin_fudai_detail.read_fudai_detail_once, - close_detail_callback=douyin_fudai_detail.close_fudai_detail, - ensure_open_callback=douyin_fudai_detail.ensure_fudai_detail_open, + from douyin.core.fudai_modules.fudai_detail_helpers import ( + reread_fudai_detail_fallback, ) - # 重新读取后,更新保存的详情数据 - if detail and isinstance(detail, tuple) and len(detail) >= 6: - self._last_fudai_detail_tuple = detail - # 设置当前福袋的 content(使用 cast 帮助静态分析) - detail_t: Tuple[Any, ...] = tuple(detail) - self._current_fudai_content = ( - detail_t[0] if len(detail_t) > 0 else "" - ) + + detail = reread_fudai_detail_fallback(self) else: # 使用第一次保存的详情数据:直接参与(不进行验证) from douyin.core.fudai_modules.fudai_detail_helpers import ( diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index f16a50d..1f9fc53 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,42 @@ def log_screenshot_failed( pass +def reread_fudai_detail_fallback(analyser): + """_handle_in_fudai_detail 步骤1:未找到保存的详情数据时的兜底重读逻辑。 + + 流程: + - 写日志说明 + - 调用 read_fudai_detail_with_retries 重新读取 + - 成功则更新 _last_fudai_detail_tuple 和 _current_fudai_content + + 返回: + 重新读取的 detail(成功)或 None(失败) + """ + from douyin.fudai import douyin_fudai_detail + + try: + analyser._log_kv( + "流程", + "_handle_in_fudai_detail:未找到第一次读取的详情数据,重新读取", + ) + except Exception: + pass + + detail = douyin_fudai_detail.read_fudai_detail_with_retries( + analyser, + fudai_x=0, + read_once_callback=douyin_fudai_detail.read_fudai_detail_once, + close_detail_callback=douyin_fudai_detail.close_fudai_detail, + ensure_open_callback=douyin_fudai_detail.ensure_fudai_detail_open, + ) + + if detail and isinstance(detail, tuple) and len(detail) >= 6: + analyser._last_fudai_detail_tuple = detail + analyser._current_fudai_content = detail[0] if len(detail) > 0 else "" + + return detail + + def handle_second_open_direct_attend( analyser, start_time: float, step1_start: float ) -> bool: