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, contributing to overall project clarity. - Enhanced logging mechanisms for better consistency and debugging support.
This commit is contained in:
1 parent
4678adb8f3
commit
efaa3d3adc
36 files changed
+15075
-517
No files matched your search
+412
-50
@@ -652,15 +652,12 @@ def handle_queue_full_wait_at_earliest(
|
||||
target_pos = 0
|
||||
pos_diff = current_room_pos - target_pos
|
||||
|
||||
# 如果已经在目标位置(pos_diff == 0),不需要先回退,直接调用回调
|
||||
# 如果不在目标位置,先轻微下滑一次,确保在直播列表中
|
||||
if pos_diff != 0:
|
||||
try:
|
||||
swipe_down_back_callback()
|
||||
time.sleep(max(0.1, float(reservation_back_swipe_delay_s or 0.0)))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 直接调用回退回调,不需要预先下滑
|
||||
# 原因:
|
||||
# 1. 回退前已经进行了阶段诊断,处理了弹窗和福袋详情页等异常状态
|
||||
# 2. 如果已经在直播间,不需要下滑
|
||||
# 3. 预先下滑会导致 room_pos 减1,影响后续的回退计算,导致少回退一个直播间
|
||||
|
||||
# 回退到最早开奖的预约直播间
|
||||
ok = False
|
||||
try:
|
||||
@@ -1165,15 +1162,11 @@ def process_reservation_attend_window(
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 如果已经在目标位置(pos_diff == 0),不需要先回退,直接调用回调
|
||||
# 如果不在目标位置,先轻微下滑一次,确保在直播列表中 / 或触发系统返回
|
||||
if pos_diff != 0:
|
||||
try:
|
||||
swipe_down_back_callback()
|
||||
time.sleep(max(0.1, float(reservation_back_swipe_delay_s or 0.0)))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 直接调用回退回调,不需要预先下滑
|
||||
# 原因:
|
||||
# 1. 回退前已经进行了阶段诊断,处理了弹窗和福袋详情页等异常状态
|
||||
# 2. 如果已经在直播间,不需要下滑
|
||||
# 3. 预先下滑会导致 room_pos 减1,影响后续的回退计算,导致少回退一个直播间
|
||||
ok = False
|
||||
try:
|
||||
ok = bool(seek_reservation_room_callback(target))
|
||||
@@ -1190,6 +1183,265 @@ def process_reservation_attend_window(
|
||||
ok = False
|
||||
|
||||
if ok:
|
||||
# 获取目标直播间名字和福袋详情(用于日志和校验)
|
||||
target_room_title = str(target.get("room_title") or "").strip()
|
||||
target_room_title_raw = str(target.get("room_title_raw") or "").strip()
|
||||
target_content = str(target.get("content") or "").strip()
|
||||
target_value = float(target.get("prize_value_yuan") or 0.0)
|
||||
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window:回退操作成功,准备进行回退校验",
|
||||
target_pos=int(target.get("pos_seen", 0)),
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
target_room_title_raw=target_room_title_raw[:50] if target_room_title_raw else "",
|
||||
target_content=target_content[:50] if target_content else "",
|
||||
target_value_yuan=target_value,
|
||||
current_room_pos=int(room_pos),
|
||||
reservation_back_verify_enabled=bool(getattr(analyser, "reservation_back_verify_enabled", True)),
|
||||
level="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 回退成功后,进行回退校验(如果启用了回退校验)
|
||||
verify_ok = True
|
||||
verify_detail = None
|
||||
try:
|
||||
verify_enabled = bool(getattr(analyser, "reservation_back_verify_enabled", True))
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window:检查回退校验开关",
|
||||
reservation_back_verify_enabled=verify_enabled,
|
||||
level="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if verify_enabled:
|
||||
try:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window:开始调用回退校验函数",
|
||||
target_pos=int(target.get("pos_seen", 0)),
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
level="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
import douyin_reservation_verify
|
||||
verify_ok, verify_detail = douyin_reservation_verify.validate_back_to_reservation(
|
||||
analyser=analyser,
|
||||
item=target,
|
||||
quick=False,
|
||||
max_checks=3,
|
||||
)
|
||||
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window:回退校验函数返回",
|
||||
verify_ok=verify_ok,
|
||||
verify_detail_exists=verify_detail is not None,
|
||||
level="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
if not verify_ok:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 回退校验失败:回退操作成功但校验未通过,尝试根据映射表自动回退到正确位置",
|
||||
target_pos=int(target.get("pos_seen", 0)),
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 校验失败,尝试根据映射表查找正确位置并自动回退
|
||||
try:
|
||||
if hasattr(analyser, "_find_room_pos_by_title"):
|
||||
correct_pos = analyser._find_room_pos_by_title(
|
||||
target_room_title, target_room_title_raw
|
||||
)
|
||||
if correct_pos is not None and correct_pos != int(target.get("pos_seen", 0)):
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 根据映射表找到正确位置,自动回退",
|
||||
original_target_pos=int(target.get("pos_seen", 0)),
|
||||
correct_pos=correct_pos,
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 更新目标位置并重新回退
|
||||
target["pos_seen"] = correct_pos
|
||||
try:
|
||||
retry_ok = bool(seek_reservation_room_callback(target))
|
||||
if retry_ok:
|
||||
# 重新进行校验
|
||||
try:
|
||||
verify_ok_retry, verify_detail_retry = douyin_reservation_verify.validate_back_to_reservation(
|
||||
analyser=analyser,
|
||||
item=target,
|
||||
quick=False,
|
||||
max_checks=3,
|
||||
)
|
||||
if verify_ok_retry:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 根据映射表自动回退后校验通过",
|
||||
correct_pos=correct_pos,
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
verify_ok = True
|
||||
verify_detail = verify_detail_retry
|
||||
ok = True
|
||||
else:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 根据映射表自动回退后校验仍失败",
|
||||
correct_pos=correct_pos,
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
ok = False
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 根据映射表自动回退后重新校验时出错",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
ok = False
|
||||
else:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 根据映射表自动回退操作失败",
|
||||
correct_pos=correct_pos,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
ok = False
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 根据映射表自动回退时出错",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
ok = False
|
||||
elif correct_pos is None:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 映射表中未找到目标直播间,无法自动回退",
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
ok = False
|
||||
else:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 映射表中的位置与目标位置相同,但校验仍失败",
|
||||
target_pos=int(target.get("pos_seen", 0)),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
ok = False
|
||||
else:
|
||||
ok = False
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 根据映射表自动回退时发生异常",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
ok = False
|
||||
else:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 回退校验通过:已成功回退到目标直播间并验证福袋详情",
|
||||
target_pos=int(target.get("pos_seen", 0)),
|
||||
target_room_title=target_room_title[:50] if target_room_title else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 回退校验执行时发生异常,继续执行",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 校验异常不影响主流程,继续执行
|
||||
else:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 回退校验已禁用,跳过校验",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 检查回退校验开关时发生异常,继续执行",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 如果回退或校验失败,直接返回 False
|
||||
if not ok:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 回退或校验失败,保留队列以便后续重试或清理",
|
||||
future_ts=int(ft),
|
||||
now_ts=int(now_ts),
|
||||
remain_seconds_to_open=int(ft - now_ts),
|
||||
target_pos=int(target.get("pos_seen", 0)),
|
||||
current_room_pos=int(room_pos),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
write_state_callback()
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
# 进入锁定期:在开奖附近一段时间内不再切换直播间
|
||||
focus_until_new = ft + max(0.0, poll_before)
|
||||
if reservation_focus_until_ts_ref:
|
||||
@@ -1201,14 +1453,6 @@ def process_reservation_attend_window(
|
||||
reservation_after_action_pending_ref[0] = True
|
||||
else:
|
||||
reservation_after_action_pending_ref.append(True)
|
||||
|
||||
# 回退过程中只执行回退操作,不进行校验或读取预约数据
|
||||
|
||||
# 获取目标直播间名字和福袋详情
|
||||
target_room_title = str(target.get("room_title") or "").strip()
|
||||
target_room_title_raw = str(target.get("room_title_raw") or "").strip()
|
||||
target_content = str(target.get("content") or "").strip()
|
||||
target_value = float(target.get("prize_value_yuan") or 0.0)
|
||||
|
||||
try:
|
||||
from datetime import datetime
|
||||
@@ -1344,6 +1588,37 @@ def record_high_value_reservation(
|
||||
- 返回 False,表示当前轮不需要立即抢占主流程。
|
||||
"""
|
||||
try:
|
||||
# 验证输入参数
|
||||
try:
|
||||
if not isinstance(fudai_content_text, str):
|
||||
fudai_content_text = str(fudai_content_text or "")
|
||||
if not isinstance(prize_value_yuan, (int, float)):
|
||||
prize_value_yuan = float(prize_value_yuan or 0.0)
|
||||
if not isinstance(future_timestamp, (int, float)) or future_timestamp <= 0:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation:future_timestamp 无效",
|
||||
future_timestamp=future_timestamp,
|
||||
error_type="InvalidParameter",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
if not isinstance(room_pos, int):
|
||||
room_pos = int(room_pos or 0)
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation:参数验证失败",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
# 计算 future_str(预计开奖时间的字符串格式)
|
||||
future_str = ""
|
||||
try:
|
||||
@@ -1353,32 +1628,106 @@ def record_high_value_reservation(
|
||||
future_str = datetime.fromtimestamp(float(future_timestamp)).strftime(
|
||||
"%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation:计算 future_str 失败",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
item: ReservationItem = {
|
||||
"future_ts": float(future_timestamp or 0.0),
|
||||
"future_str": future_str,
|
||||
"prize_value_yuan": float(prize_value_yuan or 0.0),
|
||||
"content": str(fudai_content_text or ""),
|
||||
"pos_seen": int(room_pos),
|
||||
"created_ts": _now_ts(),
|
||||
"room_title": str(room_title or ""),
|
||||
"room_title_raw": str(room_title_raw or ""),
|
||||
"task_count": int(task_count or 2),
|
||||
"time_text": str(time_text or ""),
|
||||
"participants": int(participants or 0),
|
||||
"copies": int(copies or 0),
|
||||
}
|
||||
# 验证 reservations 列表
|
||||
if not isinstance(reservations, list):
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation:reservations 不是列表",
|
||||
reservations_type=type(reservations).__name__,
|
||||
error_type="InvalidParameter",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
add_reservation_callback(reservations, item)
|
||||
sort_reservations_callback()
|
||||
# 构造预约项
|
||||
try:
|
||||
item: ReservationItem = {
|
||||
"future_ts": float(future_timestamp or 0.0),
|
||||
"future_str": future_str,
|
||||
"prize_value_yuan": float(prize_value_yuan or 0.0),
|
||||
"content": str(fudai_content_text or ""),
|
||||
"pos_seen": int(room_pos),
|
||||
"created_ts": _now_ts(),
|
||||
"room_title": str(room_title or ""),
|
||||
"room_title_raw": str(room_title_raw or ""),
|
||||
"task_count": int(task_count or 2),
|
||||
"time_text": str(time_text or ""),
|
||||
"participants": int(participants or 0),
|
||||
"copies": int(copies or 0),
|
||||
}
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation:构造预约项失败",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
prize_value_yuan=prize_value_yuan,
|
||||
future_timestamp=future_timestamp,
|
||||
room_pos=room_pos,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
# 调用回调函数添加预约
|
||||
try:
|
||||
add_reservation_callback(reservations, item)
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation:add_reservation_callback 失败",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
queue_len_before=len(reservations),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
# 排序预约队列
|
||||
try:
|
||||
sort_reservations_callback()
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation:sort_reservations_callback 失败",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 写入状态文件
|
||||
try:
|
||||
write_state_callback()
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation:write_state_callback 失败",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 记录成功日志
|
||||
try:
|
||||
from datetime import datetime
|
||||
created_str = datetime.fromtimestamp(item["created_ts"]).strftime("%Y-%m-%d %H:%M:%S")
|
||||
@@ -1399,17 +1748,30 @@ def record_high_value_reservation(
|
||||
copies=copies,
|
||||
queue_len=len(reservations),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation:记录成功日志失败",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return False
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
# 任何异常都不影响主流程,只记录日志
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] record_high_value_reservation 异常,忽略本次预约",
|
||||
error_type="Exception",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
prize_value_yuan=prize_value_yuan,
|
||||
future_timestamp=future_timestamp,
|
||||
room_pos=room_pos,
|
||||
room_title=room_title[:50] if room_title else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in new issue
Block a user