fix: Clean up blank lines and enhance readability across multiple files

- Removed excessive blank lines from various markdown and Python files to improve readability and maintainability.
- Ensured consistent formatting across documentation and code files, enhancing overall project clarity.
- Updated configuration settings and logging mechanisms for better consistency and debugging support.
This commit is contained in:
Your Name committed 2025-12-26 09:16:29 +08:00
1 parent 235c5076eb
commit 5a55265e9a
30 files changed
+3319 -51

No files matched your search

File diff suppressed because it is too large. Load diff
+2
View File
@@ -165,6 +165,8 @@ python cleanup_unused_files.py
+2
View File
@@ -176,6 +176,8 @@ except Exception as e:
+2
View File
@@ -379,6 +379,8 @@ self.last_fudai_x: int = 0 # 上次检测到的福袋图标X坐标
+2
View File
@@ -263,6 +263,8 @@ YYYYMMDD_HHMMSS_操作类型_图片名_步骤_坐标_额外信息.png
+2
View File
@@ -234,6 +234,8 @@ python check_dependencies.py
+2
View File
@@ -213,6 +213,8 @@ douyin_guaji
+2
View File
@@ -154,6 +154,8 @@
+2
View File
@@ -366,6 +366,8 @@ douyin_fudai_finder.py
+2
View File
@@ -165,6 +165,8 @@ self.ocr = easyocr.Reader(
+2
View File
@@ -124,6 +124,8 @@ python 生成WPS流程图.py
+2
View File
@@ -138,6 +138,8 @@ else:
+2 -2
View File
@@ -12,7 +12,7 @@
"fansclub_fail_action": "switch",
"high_value_fudai_enabled": true,
"high_value_fudai_threshold_yuan": 500.0,
"high_value_fudai_join_ahead_seconds": 90,
"high_value_fudai_join_ahead_seconds": 60,
"high_value_fudai_max_swipe_back": 50,
"high_value_fudai_max_reservations": 3,
"high_value_fudai_after_action": "continue",
@@ -28,7 +28,7 @@
"yanghao_fallback_enter_live_x": 540,
"yanghao_fallback_enter_live_y": 1200,
"fudai_find_max_attempts": 99999,
"fudai_icon_retry_delay_seconds": 0.3,
"fudai_icon_retry_delay_seconds": 0.4,
"fudai_icon_max_wait_seconds": 4.0,
"fudai_click_wait_seconds": 1.7,
"yanghao_recommend_duration_seconds": 206,
+193 -20
View File
@@ -1924,40 +1924,139 @@ class fudai_analyse:
try:
import json
if os.path.exists(self._reservations_state_path):
try:
self._log_kv(
"预约",
"[预约] 开始从状态文件加载预约数据",
file_path=self._reservations_state_path,
)
except Exception:
pass
with open(self._reservations_state_path, "r", encoding="utf-8") as f:
state_data = json.load(f)
reservations_from_file = state_data.get("reservations", [])
if reservations_from_file:
try:
self._log_kv(
"预约",
"[预约] 从状态文件读取到预约数据",
file_count=len(reservations_from_file),
)
except Exception:
pass
if reservations_from_file:
# 如果状态文件中有预约数据,更新 self.reservations
if not hasattr(self, "reservations") or self.reservations is None:
self.reservations = []
# 合并预约数据(避免重复)
existing_future_ts = {r.get("future_ts") for r in self.reservations if r.get("future_ts")}
for r in reservations_from_file:
if r.get("future_ts") and r.get("future_ts") not in existing_future_ts:
self.reservations.append(r)
# 排序预约队列
# 使用 add_reservation_core_logic 函数处理去重,确保与记录预约时使用相同的去重策略
# 去重策略:(future_ts, content) 相同则视为同一条记录,保留价值更高的那条
try:
douyin_reservation_logic._sort_reservations_inplace(self.reservations) # type: ignore[attr-defined]
except Exception:
pass
max_reservations = int(
getattr(self, "high_value_fudai_max_reservations", 3) or 3
)
before_count = len(self.reservations)
for r in reservations_from_file:
if not r.get("future_ts"):
continue
# 使用 add_reservation_core_logic 处理去重和队列管理
douyin_reservation_logic.add_reservation_core_logic( # type: ignore[attr-defined]
reservations=self.reservations,
item=dict(r),
max_reservations=max_reservations,
analyser=self,
write_state_callback=None, # 加载时不需要写回状态文件
)
after_count = len(self.reservations)
added_count = len(reservations_from_file)
# 记录加载统计
try:
# 输出加载后的预约详情
loaded_reservations_detail = []
for idx, r in enumerate(self.reservations[:3]): # 只显示前3个
try:
ft = float(r.get("future_ts") or 0)
from datetime import datetime
ft_str = datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") if ft > 0 else "无效"
loaded_reservations_detail.append({
"index": idx,
"future_ts": int(ft) if ft > 0 else 0,
"future_str": ft_str,
"value": float(r.get("prize_value_yuan", 0)),
})
except Exception:
pass
self._log_kv(
"预约",
"[预约] 从状态文件加载预约数据完成",
file_count=added_count,
before_count=before_count,
after_count=after_count,
duplicates_removed=added_count - (after_count - before_count),
loaded_reservations_detail=loaded_reservations_detail,
)
except Exception:
pass
except Exception as e:
try:
self._log_kv(
"预约",
"[预约] 从状态文件合并预约数据时出错",
error=str(e),
error_type=type(e).__name__,
)
except Exception:
pass
except Exception as e:
try:
self._log_kv(
"预约",
"[预约] 从状态文件加载预约数据失败",
error=str(e),
error_type=type(e).__name__,
)
except Exception:
pass
try:
self._log_kv(
"预约",
"[预约] 从状态文件加载预约数据失败",
error=str(e),
error_type=type(e).__name__,
file_path=self._reservations_state_path,
file_exists=os.path.exists(self._reservations_state_path) if hasattr(os, 'path') else False,
)
except Exception:
pass
else:
# 状态文件不存在
try:
self._log_kv(
"预约",
"[预约] 状态文件不存在,跳过加载",
file_path=self._reservations_state_path,
)
except Exception:
pass
high_value_enabled = getattr(self, "high_value_fudai_enabled", False)
reservations_list = getattr(self, "reservations", None)
reservations_count = len(reservations_list) if reservations_list else 0
# 添加调试日志,确认预约回退逻辑的触发条件
# 添加详细的调试日志,确认预约回退逻辑的触发条件
try:
# 输出预约队列的详细信息
reservations_detail = []
if reservations_list:
for idx, r in enumerate(reservations_list[:3]): # 只显示前3个
try:
ft = float(r.get("future_ts") or 0)
from datetime import datetime
ft_str = datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") if ft > 0 else "无效"
reservations_detail.append({
"index": idx,
"future_ts": int(ft) if ft > 0 else 0,
"future_str": ft_str,
"value": float(r.get("prize_value_yuan", 0)),
"pos_seen": int(r.get("pos_seen", 0)),
})
except Exception:
pass
self._log_kv(
"预约",
"[预约] run_once_basic:检查预约回退触发条件",
@@ -1965,10 +2064,32 @@ class fudai_analyse:
reservations_count=reservations_count,
reservations_is_none=(reservations_list is None),
will_check_reservations=bool(high_value_enabled and reservations_list),
reservations_detail=reservations_detail,
)
except Exception:
pass
# 如果预约功能未启用,输出日志
if not high_value_enabled:
try:
self._log_kv(
"预约",
"[预约] 预约功能未启用(high_value_fudai_enabled=False),跳过预约回退检查",
)
except Exception:
pass
# 如果预约队列为空,输出日志
elif not reservations_list or reservations_count == 0:
try:
self._log_kv(
"预约",
"[预约] 预约队列为空,跳过预约回退检查",
reservations_is_none=(reservations_list is None),
reservations_count=reservations_count,
)
except Exception:
pass
if high_value_enabled and reservations_list:
def _swipe_down_once() -> None:
@@ -2148,8 +2269,30 @@ class fudai_analyse:
except Exception:
needswitch_cfg = True
# 添加调试日志,确认 needswitch 的值
# 添加详细的调试日志,确认 needswitch 的值和预约信息
try:
# 输出第一个预约的详细信息
first_reservation_info = {}
if self.reservations and len(self.reservations) > 0:
first_r = self.reservations[0]
try:
ft = float(first_r.get("future_ts") or 0)
from datetime import datetime
import time as time_module
now_ts = time_module.time()
ft_str = datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") if ft > 0 else "无效"
remain_seconds = int(ft - now_ts) if ft > 0 else 0
first_reservation_info = {
"future_ts": int(ft) if ft > 0 else 0,
"future_str": ft_str,
"value": float(first_r.get("prize_value_yuan", 0)),
"pos_seen": int(first_r.get("pos_seen", 0)),
"remain_seconds": remain_seconds,
"current_room_pos": int(getattr(self, "room_pos", 0) or 0),
}
except Exception:
pass
self._log_kv(
"预约",
"[预约] run_once_basic:检查预约回退条件",
@@ -2157,12 +2300,23 @@ class fudai_analyse:
reservations_count=(
len(self.reservations) if self.reservations else 0
),
first_reservation=first_reservation_info,
)
except Exception:
pass
if needswitch_cfg:
# 多间模式:需要回退到预约直播间
try:
self._log_kv(
"预约",
"[预约] 多间模式:开始调用 process_reservation_attend_window",
reservations_count=len(self.reservations) if self.reservations else 0,
room_pos=int(getattr(self, "room_pos", 0) or 0),
)
except Exception:
pass
preempted = (
douyin_reservation_logic.process_reservation_attend_window(
analyser=self,
@@ -2179,6 +2333,16 @@ class fudai_analyse:
write_state_callback=_write_state,
)
)
try:
self._log_kv(
"预约",
"[预约] process_reservation_attend_window 返回结果",
preempted=preempted,
focus_until=int(focus_ref[0]) if focus_ref and focus_ref[0] > 0 else 0,
)
except Exception:
pass
# 同步回写 ref 值
if focus_ref:
self.reservation_focus_until_ts = float(focus_ref[0] or 0.0)
@@ -2199,6 +2363,15 @@ class fudai_analyse:
else:
# 单间模式:不需要回退,预约会在当前直播间自动识别和参与
# 只需要清理过期的预约
try:
self._log_kv(
"预约",
"[预约] 单间模式(needswitch=False):不执行预约回退,预约会在当前直播间自动识别和参与",
reservations_count=len(self.reservations) if self.reservations else 0,
)
except Exception:
pass
try:
import douyin_reservation_logic
+73 -7
View File
@@ -379,12 +379,23 @@ def process_reservation_attend_window(
sort_reservations_callback: Callable[[], None],
write_state_callback: Callable[[], None],
) -> bool:
"""在主循环中调用:处理“是否需要回退到某个预约直播间并参与”。
"""在主循环中调用:处理"是否需要回退到某个预约直播间并参与"。
返回:
bool: 若为 True,表示已经触发了回退/跳转,本轮主循环应尽快结束,
让上层逻辑继续后续处理(例如识别详情并参与)。
"""
# 添加函数入口日志
try:
analyser._log_kv(
"预约",
"[预约] process_reservation_attend_window 函数入口",
reservations_count=len(reservations) if reservations else 0,
room_pos=room_pos,
)
except Exception:
pass
if not reservations:
try:
analyser._log_kv(
@@ -410,6 +421,22 @@ def process_reservation_attend_window(
except Exception:
ft = 0.0
# 添加目标预约的详细信息日志
try:
from datetime import datetime
ft_str = datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") if ft > 0 else "无效"
analyser._log_kv(
"预约",
"[预约] process_reservation_attend_window 获取目标预约",
target_future_ts=int(ft) if ft > 0 else 0,
target_future_str=ft_str,
target_value=float(target.get("prize_value_yuan", 0)),
target_pos_seen=int(target.get("pos_seen", 0)),
target_content=str(target.get("content", ""))[:50],
)
except Exception:
pass
# 没有合法 future_ts,则直接丢弃
if ft <= 0:
try:
@@ -462,18 +489,37 @@ def process_reservation_attend_window(
except Exception:
dynamic_ahead = int(join_ahead)
# 添加调试日志:记录锁定期状态和时间窗口检查结果
# 添加详细的调试日志:记录锁定期状态和时间窗口检查结果
try:
from datetime import datetime
now_str = datetime.fromtimestamp(now_ts).strftime("%Y-%m-%d %H:%M:%S")
time_window_start_ts = ft - dynamic_ahead
time_window_start_str = datetime.fromtimestamp(time_window_start_ts).strftime("%Y-%m-%d %H:%M:%S") if time_window_start_ts > 0 else "无效"
time_window_end_ts = ft + max(0.0, poll_before)
time_window_end_str = datetime.fromtimestamp(time_window_end_ts).strftime("%Y-%m-%d %H:%M:%S") if time_window_end_ts > 0 else "无效"
ft_str = datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") if ft > 0 else "无效"
analyser._log_kv(
"预约",
"[预约] process_reservation_attend_window 检查",
"[预约] process_reservation_attend_window 详细检查",
now_ts=int(now_ts),
now_str=now_str,
focus_until=int(focus_until) if focus_until > 0 else 0,
target_future_ts=int(ft),
target_future_str=ft_str,
dynamic_ahead=dynamic_ahead,
time_window_start=int(ft - dynamic_ahead),
join_ahead=join_ahead,
poll_before=poll_before,
est_back_times=est_back_times,
time_window_start=int(time_window_start_ts),
time_window_start_str=time_window_start_str,
time_window_end=int(time_window_end_ts),
time_window_end_str=time_window_end_str,
remain_seconds_to_open=int(ft - now_ts) if ft > now_ts else 0,
remain_seconds_to_window=int(time_window_start_ts - now_ts) if time_window_start_ts > now_ts else 0,
in_lock_period=bool(focus_until > 0 and now_ts < focus_until),
in_time_window=bool(now_ts >= ft - dynamic_ahead),
in_time_window=bool(now_ts >= time_window_start_ts),
passed_time_window=bool(now_ts > time_window_end_ts),
)
except Exception:
pass
@@ -568,11 +614,31 @@ def process_reservation_attend_window(
except Exception:
pass
# 调用上层提供的“按预约信息回退到目标直播间”的回调
# 调用上层提供的"按预约信息回退到目标直播间"的回调
try:
analyser._log_kv(
"预约",
"[预约] 准备执行回退到预约直播间",
target_pos_seen=int(target.get("pos_seen", 0)),
current_room_pos=room_pos,
pos_diff=int(room_pos) - int(target.get("pos_seen", 0)),
)
except Exception:
pass
ok = False
try:
ok = bool(seek_reservation_room_callback(target))
except Exception:
except Exception as e:
try:
analyser._log_kv(
"预约",
"[预约] 执行回退时发生异常",
error=str(e),
error_type=type(e).__name__,
)
except Exception:
pass
ok = False
if ok:
+2
View File
@@ -138,6 +138,8 @@ def extract_participants_count(text: Optional[str]) -> int:
+2
View File
@@ -95,6 +95,8 @@ paddlepaddle>=2.5.0,<3.0.0
+2
View File
@@ -72,6 +72,8 @@ types-requests>=2.31.0
+2
View File
@@ -111,6 +111,8 @@ ttkbootstrap>=1.10.0
+2
View File
@@ -148,6 +148,8 @@ if __name__ == "__main__":
+2
View File
@@ -71,6 +71,8 @@ if os.path.exists(log_file):
+2
View File
@@ -84,6 +84,8 @@ if os.path.exists(log_file):
+2
View File
@@ -217,6 +217,8 @@ pytest --pdb --pdbcls=IPython.terminal.debugger:Pdb
+2
View File
@@ -54,6 +54,8 @@ __version__ = "1.0.0"
+2
View File
@@ -43,6 +43,8 @@
+2
View File
@@ -43,6 +43,8 @@
+2
View File
@@ -133,6 +133,8 @@ python check_gpu_available.py
+2
View File
@@ -139,6 +139,8 @@
+2
View File
@@ -211,6 +211,8 @@ if __name__ == "__main__":
+2
View File
@@ -142,3 +142,5 @@