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 logging mechanisms for better consistency and debugging support.
This commit is contained in:
Your Name committed 2025-12-26 12:01:40 +08:00
1 parent ea4cb7552f
commit d0702c863f
31 files changed
+2151 -77

No files matched your search

+1
View File
@@ -168,5 +168,6 @@ python cleanup_unused_files.py
+1
View File
@@ -179,5 +179,6 @@ except Exception as e:
+1
View File
@@ -382,5 +382,6 @@ self.last_fudai_x: int = 0 # 上次检测到的福袋图标X坐标
+1
View File
@@ -266,5 +266,6 @@ YYYYMMDD_HHMMSS_操作类型_图片名_步骤_坐标_额外信息.png
+1
View File
@@ -237,5 +237,6 @@ python check_dependencies.py
+1
View File
@@ -216,5 +216,6 @@ douyin_guaji
+1
View File
@@ -157,5 +157,6 @@
+1
View File
@@ -369,5 +369,6 @@ douyin_fudai_finder.py
+1
View File
@@ -168,5 +168,6 @@ self.ocr = easyocr.Reader(
+1
View File
@@ -127,5 +127,6 @@ python 生成WPS流程图.py
+1
View File
@@ -141,5 +141,6 @@ else:
+37 -48
View File
@@ -214,11 +214,13 @@ class fudai_analyse:
# —— 预约运行时状态(单次运行内有效) ——
# 高价值福袋预约队列
self.reservations: list[dict[str, Any]] = []
# 当前“直播间位置”计数:上划 +1,下滑 -1(仅在本次连续切换过程中有效)
# 标记是否是第一次运行 run_once_basic(用于刷新预约队列)
self._first_run_once_basic: bool = True
# 当前"直播间位置"计数:上划 +1,下滑 -1(仅在本次连续切换过程中有效)
self.room_pos: int = 0
# 回退到预约直播间后,在该时间戳前不允许上划离开
self.reservation_focus_until_ts: float = 0.0
# 当前是否还有“完成某个预约后的后续动作”待执行
# 当前是否还有"完成某个预约后的后续动作"待执行
self.reservation_after_action_pending: bool = False
# 达到"无福袋切换阈值"后,是否在处理完预约后回到列表第一个直播间
self.reset_to_list_after_reservations: bool = False
@@ -1924,12 +1926,33 @@ class fudai_analyse:
# 从状态文件加载预约数据,确保 self.reservations 始终包含最新数据
try:
import json
# 如果是第一次运行,先清空预约队列,然后重新加载(刷新预约队列)
is_first_run = getattr(self, "_first_run_once_basic", True)
if is_first_run:
try:
self._log_kv(
"预约",
"[预约] 第一次运行:清空预约队列并重新加载",
)
except Exception:
pass
# 清空预约队列
if hasattr(self, "reservations"):
self.reservations = []
# 标记已运行过
try:
self._first_run_once_basic = False
except Exception:
pass
if os.path.exists(self._reservations_state_path):
try:
self._log_kv(
"预约",
"[预约] 开始从状态文件加载预约数据",
file_path=self._reservations_state_path,
is_first_run=is_first_run,
)
except Exception:
pass
@@ -2012,6 +2035,16 @@ class fudai_analyse:
)
except Exception:
pass
else:
# 状态文件不存在
try:
self._log_kv(
"预约",
"[预约] 状态文件不存在,跳过加载",
file_path=self._reservations_state_path,
)
except Exception:
pass
except Exception as e:
try:
self._log_kv(
@@ -2024,16 +2057,6 @@ class fudai_analyse:
)
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)
@@ -3352,42 +3375,8 @@ class fudai_analyse:
except Exception:
time.sleep(delay_s)
# 如果启用了回退校验,进行详细校验
try:
if bool(getattr(self, "reservation_back_verify_enabled", True)):
import douyin_reservation_verify
is_valid, detail_tuple = (
douyin_reservation_verify.validate_back_to_reservation(
self, item, quick=False
)
)
if not is_valid:
try:
self._log_kv(
"预约", "[预约] _seek_reservation_room 回退校验失败"
)
except Exception:
pass
return False
# 校验通过,保存详情供后续使用
if detail_tuple:
try:
self._forced_reservation_detail = detail_tuple # type: ignore[attr-defined]
self._forced_reservation_fudai_x = None # type: ignore[attr-defined]
except Exception:
pass
except Exception as e:
try:
self._log_kv(
"预约", "[预约] _seek_reservation_room 回退校验异常", error=str(e)
)
except Exception:
pass
# 校验异常时,如果配置要求必须校验,则返回失败
if bool(getattr(self, "reservation_back_verify_enabled", True)):
return False
# 回退过程中只执行回退操作,不进行校验或读取预约数据
# 回退完成后直接返回成功
return True
# ========== 福袋相关 ==========
+78 -2
View File
@@ -692,7 +692,68 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
extra: Dict[str, Any] = {
"task_count": task_count,
}
# 输出所有识别到的内容到运行日志和行为日志
try:
from datetime import datetime
# 格式化时间戳为可读格式
countdown_start_str = ""
countdown_end_str = ""
if countdown_start and countdown_end:
try:
if countdown_start > 0:
countdown_start_str = datetime.fromtimestamp(countdown_start).strftime("%Y-%m-%d %H:%M:%S")
if countdown_end > 0:
countdown_end_str = datetime.fromtimestamp(countdown_end).strftime("%Y-%m-%d %H:%M:%S")
except Exception:
pass
# 计算剩余秒数
remain_seconds = 0
if countdown_end > countdown_start:
remain_seconds = int(countdown_end - time.time())
# 输出完整的识别结果到运行日志
analyser._log_kv(
"福袋详情",
"read_fudai_detail_once 完整识别结果",
status="ok",
task_count=task_count,
content=content or "",
content_length=len(content or ""),
time_text=time_text or "",
participants=int(participants or 0),
copies=int(copies or 0),
prize_value_yuan=float(prize_value_yuan or 0.0),
countdown_start=countdown_start,
countdown_start_str=countdown_start_str,
countdown_end=countdown_end,
countdown_end_str=countdown_end_str,
remain_seconds=remain_seconds,
elapsed_seconds=round(time.time() - start_time, 2),
)
# 输出到行为日志(使用更详细的格式)
analyser._log_kv(
"行为",
"识别福袋详情完成",
action="识别福袋详情",
result="成功",
detail={
"任务数量": task_count,
"福袋内容": content or "",
"倒计时文本": time_text or "",
"参与人数": int(participants or 0),
"福袋份数": int(copies or 0),
"奖品价值": float(prize_value_yuan or 0.0),
"倒计时开始时间": countdown_start_str if countdown_start_str else f"{countdown_start}",
"倒计时结束时间": countdown_end_str if countdown_end_str else f"{countdown_end}",
"剩余秒数": remain_seconds,
},
)
# 输出简化的运行日志(兼容原有格式)
analyser._log_kv(
"福袋详情",
"read_fudai_detail_once 结果",
@@ -706,8 +767,23 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
countdown_end=countdown_end,
task_count=task_count,
)
except Exception:
pass
except Exception as e:
# 如果详细日志输出失败,至少输出基本信息
try:
analyser._log_kv(
"福袋详情",
"read_fudai_detail_once 结果(简化)",
status="ok",
content=content or "",
time_text=time_text or "",
participants=int(participants or 0),
copies=int(copies or 0),
prize_value_yuan=float(prize_value_yuan or 0.0),
error=str(e),
)
except Exception:
pass
elapsed = time.time() - start_time
analyser._log_kv("福袋详情", "read_fudai_detail_once完成(成功)", elapsed_seconds=round(elapsed, 2))
return "ok", detail_tuple, extra
+34 -5
View File
@@ -563,13 +563,45 @@ def process_reservation_attend_window(
pass
return False
# 是同一个预约,即使锁定期还没结束,如果时间窗口到了,也允许回退
# 但这里通常已经在目标直播间了,所以继续检查时间窗口
# 但这里通常已经在目标直播间了,需要检查是否已经在目标位置
# 获取当前实际的 room_pos(可能已经被更新)
try:
current_room_pos_check = int(getattr(analyser, "room_pos", room_pos) or room_pos)
except Exception:
current_room_pos_check = int(room_pos)
# 计算位置差
try:
target_pos_check = int(target.get("pos_seen") or 0)
except Exception:
target_pos_check = 0
pos_diff_check = current_room_pos_check - target_pos_check
# 如果已经在目标位置(pos_diff == 0),说明已经在目标直播间,不需要再次回退
if pos_diff_check == 0:
try:
analyser._log_kv(
"预约",
"[预约] 锁定期未结束但是同一个预约,且已在目标位置,跳过回退",
focus_until=int(focus_until),
target_future_ts=int(ft),
current_room_pos=current_room_pos_check,
target_pos=target_pos_check,
)
except Exception:
pass
return False
# 如果不在目标位置,继续检查时间窗口
try:
analyser._log_kv(
"预约",
"[预约] 锁定期未结束但是同一个预约,继续检查时间窗口",
focus_until=int(focus_until),
target_future_ts=int(ft),
current_room_pos=current_room_pos_check,
target_pos=target_pos_check,
pos_diff=pos_diff_check,
)
except Exception:
pass
@@ -684,10 +716,7 @@ def process_reservation_attend_window(
else:
reservation_after_action_pending_ref.append(True)
try:
validate_back_to_reservation(analyser, reservations, now_ts=_now_ts())
except Exception:
pass
# 回退过程中只执行回退操作,不进行校验或读取预约数据
try:
analyser._log_kv(
+1
View File
@@ -141,5 +141,6 @@ def extract_participants_count(text: Optional[str]) -> int:
+1
View File
@@ -98,5 +98,6 @@ paddlepaddle>=2.5.0,<3.0.0
+1
View File
@@ -75,5 +75,6 @@ types-requests>=2.31.0
+1
View File
@@ -114,5 +114,6 @@ ttkbootstrap>=1.10.0
+1
View File
@@ -151,5 +151,6 @@ if __name__ == "__main__":
+21 -21
View File
@@ -1,29 +1,29 @@
{
"updated_ts": 1766654764.0481348,
"reason": "record_reservation",
"room_pos": 1,
"current_room_title": "小北珠宝",
"current_room_title_raw": "小北珠宝",
"updated_ts": 1766719664.092457,
"reason": "process_reservation",
"room_pos": 5,
"current_room_title": "香香生活号",
"current_room_title_raw": "香香生活号",
"reservations": [
{
"prize_value_yuan": 688.0,
"content": "28后开奖13(小北珠宝』时尚精美首饰收纳箱",
"future_ts": 1766655359.082115,
"future_str": "2025-12-25 17:35:59",
"pos_seen": 0,
"room_title": "小北珠宝",
"room_title_raw": "小北珠宝^",
"created_ts": 1766654553.7522466
"prize_value_yuan": 799.0,
"content": "25后开奖03便携式迷你小型宿舍手持电熨斗挂烫机熨烫机衣服家。400人巳参与",
"future_ts": 1766719657.646924,
"future_str": "2025-12-26 11:27:37",
"pos_seen": 5,
"room_title": "香香生活号",
"room_title_raw": "香香生活号",
"created_ts": 1766719455.111098
},
{
"prize_value_yuan": 688.0,
"content": "06后开奖10(小北珠宝』时尚精美首饰收纳箱",
"future_ts": 1766655366.269159,
"future_str": "2025-12-25 17:36:06",
"pos_seen": 1,
"room_title": "小北珠宝",
"room_title_raw": "小北珠宝",
"created_ts": 1766654764.0481348
"prize_value_yuan": 199.0,
"content": "44后开奖11KAZO0凝时奢润冻干眼膜套盒HD2A",
"future_ts": 1766720121.385851,
"future_str": "2025-12-26 11:35:21",
"pos_seen": 4,
"room_title": "王媛媛",
"room_title_raw": "王媛媛(",
"created_ts": 1766719420.0087907
}
]
}
+1
View File
@@ -74,5 +74,6 @@ if os.path.exists(log_file):
+1
View File
@@ -87,5 +87,6 @@ if os.path.exists(log_file):
+1
View File
@@ -220,5 +220,6 @@ pytest --pdb --pdbcls=IPython.terminal.debugger:Pdb
+1
View File
@@ -57,5 +57,6 @@ __version__ = "1.0.0"
+1
View File
@@ -46,5 +46,6 @@
+1
View File
@@ -46,5 +46,6 @@
+1
View File
@@ -136,5 +136,6 @@ python check_gpu_available.py
+1
View File
@@ -142,5 +142,6 @@
+1
View File
@@ -214,5 +214,6 @@ if __name__ == "__main__":
+1
View File
@@ -144,3 +144,4 @@