refactor(fudai): 抽 _handle_in_fudai_detail 步骤1"重新读取详情兜底"块到 reread_fudai_detail_fallback
将"未找到保存的详情数据时的兜底重读"逻辑(约 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) <noreply@anthropic.com>
This commit is contained in:
1 parent
d109e94c68
commit
b8ccb899c0
2 files changed
+40
-21
No files matched your search
@@ -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 (
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user