From 81b82e6cba96f8b052b046b39fb203cc939aff3e Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 12:37:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20=5Fhandle=5Fin?= =?UTF-8?q?=5Ffudai=5Fdetail=20=E4=B8=AD"=E6=8F=90=E5=8F=96=20future=5Fts"?= =?UTF-8?q?=E5=92=8C"detail=20=E4=B8=BA=20None=20=E6=97=A9=E8=BF=94?= =?UTF-8?q?=E5=9B=9E"=E4=B8=A4=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - extract_future_ts_from_detail:从 detail tuple 提取倒计时 future_ts 写入 _current_fudai_future_ts - handle_detail_none_in_step4:步骤4 detail 为 None 时的早返回处理 douyin_fudai.py: 1355 → 1341 行 (-14) fudai_detail_helpers.py: 2742 → 2776 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 32 +++++------------ .../fudai_modules/fudai_detail_helpers.py | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 77e7dca..848be9e 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1258,16 +1258,11 @@ class fudai_analyse: attend_before_ts = getattr(self, "_last_successful_attend_ts", 0.0) or 0.0 # 记录当前福袋的 future_ts,供 attend_choujiang 使用 - try: - if isinstance(detail, tuple) and len(detail) >= 6: - d_cast: Tuple[Any, ...] = cast(Tuple[Any, ...], detail) - countdown_tuple = d_cast[5] - if isinstance(countdown_tuple, (tuple, list)) and len(countdown_tuple) >= 2: - future_ts = float(countdown_tuple[1] or 0.0) - if future_ts > 0: - self._current_fudai_future_ts = future_ts - except Exception: - pass + from douyin.core.fudai_modules.fudai_detail_helpers import ( + extract_future_ts_from_detail, + ) + + extract_future_ts_from_detail(self, detail) # 重置详情关闭标志 try: @@ -1283,20 +1278,11 @@ class fudai_analyse: step4_start = time.time() # 执行参与决策 if detail is None: - try: - self._log_kv("参与", "详情数据为 None,无法执行参与决策") - except Exception: - pass - - # 清除任务数量标志 - clear_task_count_flag(self) - - elapsed = time.time() - start_time - self._log_kv( - "流程", - "_handle_in_fudai_detail完成(详情为None)", - elapsed_seconds=round(elapsed, 2), + from douyin.core.fudai_modules.fudai_detail_helpers import ( + handle_detail_none_in_step4, ) + + handle_detail_none_in_step4(self, start_time) return join_result = douyin_fudai_core.basic_join_decision( self, detail, (skip, skip_reason) diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index e10f525..1a3aa5f 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,40 @@ def log_screenshot_failed( pass +def extract_future_ts_from_detail(analyser, detail) -> None: + """从 detail tuple 中提取倒计时 future_ts 并写入 _current_fudai_future_ts。""" + try: + countdown_tuple = None + if isinstance(detail, tuple) and len(detail) >= 6: + countdown_tuple = detail[5] + if ( + isinstance(countdown_tuple, (tuple, list)) + and len(countdown_tuple) >= 2 + ): + future_ts = float(countdown_tuple[1] or 0.0) + if future_ts > 0: + analyser._current_fudai_future_ts = future_ts + except Exception: + pass + + +def handle_detail_none_in_step4(analyser, start_time: float) -> None: + """步骤 4:detail 为 None 时的早返回处理(写日志 + clear_task_count_flag)。""" + try: + analyser._log_kv("参与", "详情数据为 None,无法执行参与决策") + except Exception: + pass + + clear_task_count_flag(analyser) + + elapsed = time.time() - start_time + analyser._log_kv( + "流程", + "_handle_in_fudai_detail完成(详情为None)", + elapsed_seconds=round(elapsed, 2), + ) + + def try_skip_to_in_fudai_detail_when_verified(analyser, start_time: float) -> bool: """_handle_live_room_has_or_not_fudai 入口:如果已验证过详情页,直接处理详情。