refactor(fudai): 抽 run_once_basic 中"COUPON_POPUP"和"SHOPPING_REDPACKET_POPUP"分支到 helper

将两个简单的弹窗处理分支抽到独立 helper:
- handle_coupon_popup:按返回键关闭优惠券弹窗
- handle_shopping_redpacket_popup:点击 (530, 1647) 关闭购物红包弹窗

douyin_fudai.py: 3042 → 3022 行 (-20)
fudai_detail_helpers.py: 618 → 657 行

验证:
- pytest 1013 passed
- compile OK

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
CodexandClaude Opus 4.7 committed 2026-05-22 11:14:54 +08:00
1 parent c9a07cc91e
commit 7307b2abb5
2 files changed
+47 -28

No files matched your search

+8 -28
View File
@@ -1639,38 +1639,18 @@ class fudai_analyse:
# 处理弹窗阶段
if stage == "COUPON_POPUP":
# 优惠券弹窗:按返回键关闭
self._log_kv("弹窗处理", "检测到优惠券弹窗,按返回键关闭")
try:
self.operation.click_back(self.device_id)
self.operation.delay(0.5)
self._log_kv("弹窗处理", "已按返回键关闭优惠券弹窗")
except Exception as e:
self._log_kv("弹窗处理", "按返回键关闭优惠券弹窗失败", error=str(e))
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_coupon_popup,
)
handle_coupon_popup(self, start_time)
return
elif stage == "SHOPPING_REDPACKET_POPUP":
# 购物红包弹窗:点击关闭按钮
self._log_kv("弹窗处理", "检测到购物红包弹窗,点击关闭按钮")
try:
close_x = int(530 * self.resolution_ratio_x // 1080)
close_y = int(1647 * self.resolution_ratio_y // 2400)
self.operation.click(self.device_id, close_x, close_y)
self.operation.delay(0.5)
self._log_kv("弹窗处理", "已点击购物红包关闭按钮", x=close_x, y=close_y)
except Exception as e:
self._log_kv("弹窗处理", "点击购物红包关闭按钮失败", error=str(e))
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_shopping_redpacket_popup,
)
handle_shopping_redpacket_popup(self, start_time)
return
elif stage == "FANSCLUB_JOIN":
from douyin.core.fudai_modules.fudai_detail_helpers import (
@@ -42,6 +42,45 @@ def log_screenshot_failed(
pass
def handle_coupon_popup(analyser, start_time: float) -> None:
"""run_once_basic stage == "COUPON_POPUP" 分支:按返回键关闭优惠券弹窗。"""
analyser._log_kv("弹窗处理", "检测到优惠券弹窗,按返回键关闭")
try:
analyser.operation.click_back(analyser.device_id)
analyser.operation.delay(0.5)
analyser._log_kv("弹窗处理", "已按返回键关闭优惠券弹窗")
except Exception as e:
analyser._log_kv("弹窗处理", "按返回键关闭优惠券弹窗失败", error=str(e))
elapsed = time.time() - start_time
analyser._log_kv(
"流程",
"run_once_basic完成(处理优惠券弹窗)",
elapsed_seconds=round(elapsed, 2),
)
def handle_shopping_redpacket_popup(analyser, start_time: float) -> None:
"""run_once_basic stage == "SHOPPING_REDPACKET_POPUP" 分支:点击关闭按钮。"""
rx = analyser.resolution_ratio_x
ry = analyser.resolution_ratio_y
analyser._log_kv("弹窗处理", "检测到购物红包弹窗,点击关闭按钮")
try:
close_x = int(530 * rx // 1080)
close_y = int(1647 * ry // 2400)
analyser.operation.click(analyser.device_id, close_x, close_y)
analyser.operation.delay(0.5)
analyser._log_kv("弹窗处理", "已点击购物红包关闭按钮", x=close_x, y=close_y)
except Exception as e:
analyser._log_kv("弹窗处理", "点击购物红包关闭按钮失败", error=str(e))
elapsed = time.time() - start_time
analyser._log_kv(
"流程",
"run_once_basic完成(处理购物红包弹窗)",
elapsed_seconds=round(elapsed, 2),
)
def handle_in_live_room_stage(analyser, start_time: float) -> None:
"""run_once_basic stage in ("IN_LIVE_ROOM", "LIVE_OR_UNKNOWN") 分支: