refactor(fudai): 抽 run_once_basic 中"所有预约完成回退到第一个直播间"块到 reset_to_first_room_after_all_reservations_done
将"queue_full_waiting_at_earliest=True 且 reservations 为空时回退"独立块 (约 36 行)抽到 helper: - 写日志 - 清除 queue_full_waiting_at_earliest 和 reservation_focus_until_ts - 回退 room_pos 次(最多 100 次) - 重置 room_pos 和 _swipe_times 返回值约定: - True:触发了重置(调用方应直接 return) - False:条件不满足或异常,调用方继续 douyin_fudai.py: 1715 → 1688 行 (-27) fudai_detail_helpers.py: 2185 → 2242 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
77d7113ca1
commit
798286776d
2 files changed
+64
-34
No files matched your search
@@ -844,40 +844,13 @@ class fudai_analyse:
|
||||
pass
|
||||
|
||||
# 检查是否所有预约已完成,需要重置到第一个直播间
|
||||
if self.queue_full_waiting_at_earliest and not self.reservations:
|
||||
try:
|
||||
self._log_kv(
|
||||
"预约",
|
||||
"[预约] 所有预约已完成,重置到第一个直播间",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
self.queue_full_waiting_at_earliest = False
|
||||
self.reservation_focus_until_ts = 0.0
|
||||
# 回退到第一个直播间:需要回退 room_pos 次
|
||||
try:
|
||||
current_pos = int(getattr(self, "room_pos", 0) or 0)
|
||||
back_times = abs(current_pos)
|
||||
# 防止无限循环:最大回退次数限制为100
|
||||
if back_times > 100:
|
||||
back_times = 100
|
||||
if back_times > 0:
|
||||
for i in range(back_times):
|
||||
_swipe_down_once()
|
||||
self.operation.delay(0.6)
|
||||
self.room_pos = 0
|
||||
if hasattr(self, "_swipe_times"):
|
||||
self._swipe_times = 0
|
||||
try:
|
||||
self._log_kv(
|
||||
"预约",
|
||||
"[预约] 已回退到第一个直播间",
|
||||
back_times=back_times,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
reset_to_first_room_after_all_reservations_done,
|
||||
)
|
||||
|
||||
if reset_to_first_room_after_all_reservations_done(
|
||||
self, _swipe_down_once
|
||||
):
|
||||
return
|
||||
|
||||
# 单间模式(needswitch=False)下不启用预约回退逻辑
|
||||
|
||||
@@ -42,6 +42,63 @@ def log_screenshot_failed(
|
||||
pass
|
||||
|
||||
|
||||
def reset_to_first_room_after_all_reservations_done(
|
||||
analyser, swipe_down_back_callback
|
||||
) -> bool:
|
||||
"""run_once_basic 步骤:所有预约已完成且 queue_full_waiting_at_earliest 为 True 时,
|
||||
回退到第一个直播间。
|
||||
|
||||
流程:
|
||||
- 写日志
|
||||
- 清除 queue_full_waiting_at_earliest 和 reservation_focus_until_ts
|
||||
- 回退 room_pos 次(最多 100 次)
|
||||
- 重置 room_pos 和 _swipe_times
|
||||
|
||||
返回:
|
||||
True:触发了重置,已写完成日志(调用方应直接 return)
|
||||
False:条件不满足或异常,调用方继续
|
||||
"""
|
||||
if not (
|
||||
analyser.queue_full_waiting_at_earliest and not analyser.reservations
|
||||
):
|
||||
return False
|
||||
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 所有预约已完成,重置到第一个直播间",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
analyser.queue_full_waiting_at_earliest = False
|
||||
analyser.reservation_focus_until_ts = 0.0
|
||||
|
||||
try:
|
||||
current_pos = int(getattr(analyser, "room_pos", 0) or 0)
|
||||
back_times = abs(current_pos)
|
||||
if back_times > 100:
|
||||
back_times = 100
|
||||
if back_times > 0:
|
||||
for _ in range(back_times):
|
||||
swipe_down_back_callback()
|
||||
analyser.operation.delay(0.6)
|
||||
analyser.room_pos = 0
|
||||
if hasattr(analyser, "_swipe_times"):
|
||||
analyser._swipe_times = 0
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 已回退到第一个直播间",
|
||||
back_times=back_times,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
|
||||
|
||||
def check_high_value_skip_decision(
|
||||
analyser, detail, skip_reason: str, start_time: float
|
||||
):
|
||||
|
||||
Reference in new issue
Block a user