refactor(fudai): 抽 run_once_basic 中"FUDai_RESULT"分支到 handle_lottery_result_stage
将抽奖结果弹窗处理独立块(约 30 行)抽到 fudai_detail_helpers.handle_lottery_result_stage。逻辑: - 清除 _waiting_for_lottery_result / _current_attending_reservation_fudai - OCR 识别开奖结果文本 - 命中则 _handle_lottery_result_by_ocr;未命中则返回键 + 切下个直播间 - 写完成日志 douyin_fudai.py: 3092 → 3071 行 (-21) fudai_detail_helpers.py: 535 → 572 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
da552d18cc
commit
b5d7943af0
2 files changed
+41
-25
No files matched your search
@@ -1761,32 +1761,11 @@ class fudai_analyse:
|
||||
douyin_live_room.reflash_zhibo(self)
|
||||
elif stage == "FUDai_RESULT":
|
||||
# 抽奖结果弹窗:处理开奖结果(使用OCR识别,不使用阶段诊断)
|
||||
# 清除等待开奖标志
|
||||
self._waiting_for_lottery_result = False
|
||||
self._current_attending_reservation_fudai = False
|
||||
|
||||
self._log_kv("开奖结果", "检测到抽奖结果弹窗,使用OCR识别处理")
|
||||
# 直接OCR识别并处理
|
||||
lottery_ocr_start = time.time()
|
||||
result = self._check_lottery_result_by_ocr()
|
||||
if result:
|
||||
self._handle_lottery_result_by_ocr(result)
|
||||
else:
|
||||
# OCR识别失败,使用返回键关闭
|
||||
try:
|
||||
self.operation.click_back(self.device_id)
|
||||
self.operation.delay(0.5)
|
||||
self.swipe_up_to_next_live()
|
||||
except Exception:
|
||||
pass
|
||||
lottery_ocr_elapsed = time.time() - lottery_ocr_start
|
||||
self._log_kv("开奖结果", f"OCR处理完成,耗时: {lottery_ocr_elapsed:.3f}s")
|
||||
elapsed = time.time() - start_time
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"run_once_basic完成(处理开奖结果)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
handle_lottery_result_stage,
|
||||
)
|
||||
|
||||
handle_lottery_result_stage(self, start_time)
|
||||
return
|
||||
elif stage in ("LIVE_CLOSED",):
|
||||
# 直播结束:下滑/切下一个
|
||||
|
||||
@@ -42,6 +42,43 @@ def log_screenshot_failed(
|
||||
pass
|
||||
|
||||
|
||||
def handle_lottery_result_stage(analyser, start_time: float) -> None:
|
||||
"""run_once_basic stage == "FUDai_RESULT" 分支:
|
||||
|
||||
- 清除等待开奖标志
|
||||
- OCR 识别开奖结果文本
|
||||
- 命中则交给 _handle_lottery_result_by_ocr 处理;未命中则按返回键 + 切换下一个直播间
|
||||
- 写完成日志
|
||||
|
||||
调用方应在调用后立即 return。
|
||||
"""
|
||||
# 清除等待开奖标志
|
||||
analyser._waiting_for_lottery_result = False
|
||||
analyser._current_attending_reservation_fudai = False
|
||||
|
||||
analyser._log_kv("开奖结果", "检测到抽奖结果弹窗,使用OCR识别处理")
|
||||
lottery_ocr_start = time.time()
|
||||
result = analyser._check_lottery_result_by_ocr()
|
||||
if result:
|
||||
analyser._handle_lottery_result_by_ocr(result)
|
||||
else:
|
||||
# OCR识别失败,使用返回键关闭
|
||||
try:
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
analyser.operation.delay(0.5)
|
||||
analyser.swipe_up_to_next_live()
|
||||
except Exception:
|
||||
pass
|
||||
lottery_ocr_elapsed = time.time() - lottery_ocr_start
|
||||
analyser._log_kv("开奖结果", f"OCR处理完成,耗时: {lottery_ocr_elapsed:.3f}s")
|
||||
elapsed = time.time() - start_time
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"run_once_basic完成(处理开奖结果)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
)
|
||||
|
||||
|
||||
def handle_recommend_page(analyser) -> None:
|
||||
"""run_once_basic stage == "RECOMMEND_PAGE" 分支:
|
||||
|
||||
|
||||
Reference in new issue
Block a user