refactor(fudai): 抽 _handle_in_fudai_detail 步骤1/2 分发到 step1_or_step2_dispatcher
将"is_second_open True/False 分发"块(约 44 行)整段抽到 helper: - True:检查保存的详情,有效则直接参与;无则 reread_fudai_detail_fallback 兜底 - False:调用 handle_first_open_step2 完整流程 返回 (detail, skip, skip_reason) 或 None(已早返回)。 douyin_fudai.py: 809 → 775 行 (-34) fudai_detail_helpers.py: 3174 → 3213 行 douyin_fudai.py 跌破 800 行(4121 → 775,本会话累计削减 3346 行 = -81%) _handle_in_fudai_detail 从 131 → 96 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2899c932c4
commit
df8942e7b8
2 files changed
+48
-43
No files matched your search
@@ -655,50 +655,16 @@ class fudai_analyse:
|
||||
handle_consecutive_failures_exceeded(self, max_consecutive_failures)
|
||||
return
|
||||
|
||||
# 步骤1:检查是否是第二次打开福袋详情
|
||||
step1_start = time.time()
|
||||
is_second_open = getattr(self, "_fudai_detail_first_read", False)
|
||||
# 如果是第二次打开,直接点击参与,不需要验证,使用第一次的倒计时
|
||||
is_second_open = getattr(self, "_fudai_detail_first_read", False)
|
||||
if is_second_open:
|
||||
# 第二次打开:直接点击参与,不进行验证,使用第一次的倒计时
|
||||
try:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:第二次打开,直接点击参与,跳过验证和内容识别",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 步骤1(第二次打开)vs 步骤2(第一次打开)的分发
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
step1_or_step2_dispatcher,
|
||||
)
|
||||
|
||||
# 获取第一次读取的详情数据
|
||||
detail = getattr(self, "_last_fudai_detail_tuple", None)
|
||||
if detail is None or not isinstance(detail, tuple) or len(detail) < 6:
|
||||
# 如果没有保存的详情数据,需要重新读取(兜底逻辑)
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
reread_fudai_detail_fallback,
|
||||
)
|
||||
|
||||
detail = reread_fudai_detail_fallback(self)
|
||||
else:
|
||||
# 使用第一次保存的详情数据:直接参与(不进行验证)
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
handle_second_open_direct_attend,
|
||||
)
|
||||
|
||||
if handle_second_open_direct_attend(self, start_time, step1_start):
|
||||
return
|
||||
# 异常时继续正常流程
|
||||
else:
|
||||
# 步骤2:读取福袋详情 + 数据验证 + 筛选检查
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
handle_first_open_step2,
|
||||
)
|
||||
|
||||
step2_result = handle_first_open_step2(self, start_time)
|
||||
if step2_result is None:
|
||||
return
|
||||
detail, skip, skip_reason = step2_result
|
||||
step3_start = time.time() # 兼容后续 step3_elapsed 日志
|
||||
result = step1_or_step2_dispatcher(self, start_time)
|
||||
if result is None:
|
||||
return
|
||||
detail, skip, skip_reason = result
|
||||
step3_start = time.time() # 兼容后续 step3_elapsed 日志
|
||||
|
||||
# 检查是否是优惠券弹窗、观看任务或识别错误:根据 _last_fudai_detail_status 分发到对应处理
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
|
||||
@@ -273,6 +273,45 @@ def handle_no_fudai_in_live_room(analyser, room_pos_ref, start_time: float) -> N
|
||||
)
|
||||
|
||||
|
||||
def step1_or_step2_dispatcher(analyser, start_time: float):
|
||||
"""步骤1(第二次打开)vs 步骤2(第一次打开)的分发。
|
||||
|
||||
- is_second_open=True:检查保存的详情,有效则直接参与;无则重新读取兜底
|
||||
- is_second_open=False:调用 handle_first_open_step2 完整流程
|
||||
|
||||
返回:
|
||||
- (detail, skip, skip_reason) 三元组:流程通过,调用方继续后续步骤
|
||||
- None:已早返回(参与成功 / 验证失败 / 筛选不通过 等)
|
||||
"""
|
||||
step1_start = time.time()
|
||||
is_second_open = getattr(analyser, "_fudai_detail_first_read", False)
|
||||
|
||||
if is_second_open:
|
||||
# 第二次打开
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:第二次打开,直接点击参与,跳过验证和内容识别",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
detail = getattr(analyser, "_last_fudai_detail_tuple", None)
|
||||
if detail is None or not isinstance(detail, tuple) or len(detail) < 6:
|
||||
# 未保存详情:兜底重读
|
||||
detail = reread_fudai_detail_fallback(analyser)
|
||||
else:
|
||||
# 使用保存的详情:直接参与
|
||||
if handle_second_open_direct_attend(analyser, start_time, step1_start):
|
||||
return None
|
||||
# 异常时继续正常流程
|
||||
# 第二次打开分支不返回 (skip, skip_reason);用空值占位
|
||||
return (detail, False, "")
|
||||
else:
|
||||
# 第一次打开:完整流程
|
||||
return handle_first_open_step2(analyser, start_time)
|
||||
|
||||
|
||||
def handle_first_open_step2(analyser, start_time: float):
|
||||
"""步骤2:第一次打开福袋详情。
|
||||
|
||||
|
||||
Reference in new issue
Block a user