fix: Update debug image handling and enhance reservation display

- Added a configuration option in `config.json` to enable or disable debug image saving, defaulting to false for improved performance.
- Updated the GUI and web interface to display reservation details in Chinese, enhancing readability and user experience.
- Adjusted the click coordinates for joining the fan club and added logic to close the details page after joining.
- Cleaned up blank lines across multiple files to improve code readability and maintainability.
This commit is contained in:
Your Name committed 2025-12-26 15:09:18 +08:00
1 parent 5d22250b05
commit 36b39b1fac
35 files changed
+2863 -46

No files matched your search

+110 -13
View File
@@ -507,6 +507,14 @@ def main():
value=float(cfg.get("fansclub_join_red_ratio_threshold", 0.25) or 0.25)
)
# 调试图像开关 & 清理相关变量
debug_captures_enabled_var = tk.BooleanVar(
value=bool(
cfg.get("debug_captures", {}).get("enabled", False)
if isinstance(cfg.get("debug_captures"), dict)
else False
)
)
# 调试图像清理相关变量
debug_captures_auto_cleanup_var = tk.BooleanVar(
value=bool(
@@ -878,37 +886,48 @@ def main():
debug_tab = ttk.Frame(left_notebook)
left_notebook.add(debug_tab, text="调试参数")
# 调试图像清理
debug_captures_box = ttk.LabelFrame(debug_tab, text="调试图像清理")
# 调试图像
debug_captures_box = ttk.LabelFrame(debug_tab, text="调试图像")
debug_captures_box.pack(fill=X, padx=10, pady=(10, 10))
debug_r0 = ttk.Frame(debug_captures_box)
debug_r0.pack(fill=X, padx=10, pady=(10, 8))
ttk.Checkbutton(
debug_r0, text="启用自动清理调试图像", variable=debug_captures_auto_cleanup_var
debug_r0,
text="保存调试图像(OCR / 像素 / 模板等)",
variable=debug_captures_enabled_var,
).pack(side=LEFT)
debug_r1 = ttk.Frame(debug_captures_box)
debug_r1.pack(fill=X, padx=10, pady=(0, 8))
ttk.Label(debug_r1, text="保留天数:").pack(side=LEFT)
debug_cleanup_box = ttk.LabelFrame(debug_tab, text="调试图像清理")
debug_cleanup_box.pack(fill=X, padx=10, pady=(0, 10))
debug_r1 = ttk.Frame(debug_cleanup_box)
debug_r1.pack(fill=X, padx=10, pady=(10, 8))
ttk.Checkbutton(
debug_r1, text="启用自动清理调试图像", variable=debug_captures_auto_cleanup_var
).pack(side=LEFT)
debug_r2 = ttk.Frame(debug_cleanup_box)
debug_r2.pack(fill=X, padx=10, pady=(0, 8))
ttk.Label(debug_r2, text="保留天数:").pack(side=LEFT)
ttk.Spinbox(
debug_r1,
debug_r2,
from_=1,
to=30,
increment=1,
textvariable=debug_captures_keep_days_var,
width=6,
).pack(side=LEFT)
ttk.Label(debug_r1, text="最大文件数量:").pack(side=LEFT, padx=(20, 0))
ttk.Label(debug_r2, text="最大文件数量:").pack(side=LEFT, padx=(20, 0))
ttk.Spinbox(
debug_r1,
debug_r2,
from_=100,
to=10000,
increment=100,
textvariable=debug_captures_max_files_var,
width=8,
).pack(side=LEFT)
ttk.Label(debug_r1, text="(超过此数量自动清理)").pack(side=LEFT, padx=(6, 0))
ttk.Label(debug_r2, text="(超过此数量自动清理)").pack(side=LEFT, padx=(6, 0))
# 找福袋参数
fudai_find_box = ttk.LabelFrame(debug_tab, text="找福袋参数")
@@ -1248,6 +1267,9 @@ def main():
# 调试图像清理配置
debug_captures_config = cfg.get("debug_captures", {})
if isinstance(debug_captures_config, dict):
debug_captures_enabled_var.set(
bool(debug_captures_config.get("enabled", False))
)
debug_captures_auto_cleanup_var.set(
bool(debug_captures_config.get("auto_cleanup", True))
)
@@ -1437,6 +1459,9 @@ def main():
# 调试图像清理配置
if "debug_captures" not in cfg2 or not isinstance(cfg2["debug_captures"], dict):
cfg2["debug_captures"] = {}
cfg2["debug_captures"]["enabled"] = bool(
debug_captures_enabled_var.get()
)
cfg2["debug_captures"]["auto_cleanup"] = bool(
debug_captures_auto_cleanup_var.get()
)
@@ -2732,9 +2757,81 @@ def main():
with open(path, "r", encoding="utf-8") as f:
data = json.load(f)
reservation_text.delete("1.0", "end")
reservation_text.insert(
"1.0", json.dumps(data, ensure_ascii=False, indent=2)
)
from datetime import datetime
updated_ts = float(data.get("updated_ts", 0.0) or 0.0) if isinstance(data, dict) else 0.0
room_pos = int(data.get("room_pos", 0) or 0) if isinstance(data, dict) else 0
reason = str(data.get("reason", "") or "") if isinstance(data, dict) else ""
current_title = str(data.get("current_room_title", "") or "") if isinstance(data, dict) else ""
current_title_raw = str(data.get("current_room_title_raw", "") or "") if isinstance(data, dict) else ""
reservations = data.get("reservations", []) if isinstance(data, dict) else []
# 基本信息(中文)
lines = []
lines.append("=== 预约队列总览 ===")
if updated_ts > 0:
try:
updated_str = datetime.fromtimestamp(updated_ts).strftime("%Y-%m-%d %H:%M:%S")
except Exception:
updated_str = str(updated_ts)
else:
updated_str = "-"
lines.append(f"更新时间:{updated_str}")
lines.append(f"当前直播间位置:{room_pos}")
lines.append(f"当前直播间(清洗后):{current_title or '-'}")
lines.append(f"当前直播间原文:{current_title_raw or '-'}")
lines.append(f"预约总数量:{len(reservations)}")
if reason:
lines.append(f"最近更新原因:{reason}")
lines.append("")
if not reservations:
lines.append("暂无预约记录。")
else:
lines.append("=== 预约明细列表(按预计开奖时间排序) ===")
now_ts = datetime.now().timestamp()
for idx, item in enumerate(reservations, start=1):
try:
val = float(item.get("prize_value_yuan") or 0.0)
except Exception:
val = 0.0
content = str(item.get("content") or "")
ft = float(item.get("future_ts") or 0.0)
ft_str = str(item.get("future_str") or "")
pos_seen = int(item.get("pos_seen") or 0)
room_title = str(item.get("room_title") or "")
room_title_raw = str(item.get("room_title_raw") or "")
created_ts = float(item.get("created_ts") or 0.0)
# 计算剩余时间
remain_sec = max(0, int(ft - now_ts)) if ft > 0 else 0
if remain_sec > 0:
remain_str = f"{remain_sec // 60}分{remain_sec % 60}秒后开奖"
elif ft > 0:
remain_str = "已到开奖时间"
else:
remain_str = "未知(future_ts 无效)"
# 记录时间
if created_ts > 0:
try:
created_str = datetime.fromtimestamp(created_ts).strftime("%Y-%m-%d %H:%M:%S")
except Exception:
created_str = str(created_ts)
else:
created_str = "-"
lines.append(f"[#{idx}] 价值:{val:.2f} 元")
lines.append(f" 奖品内容:{content}")
lines.append(f" 预计开奖时间:{ft_str or '-'}")
lines.append(f" 剩余时间:{remain_str}")
lines.append(f" 发现时直播间位置:{pos_seen}")
lines.append(f" 直播间(清洗后):{room_title or '-'}")
lines.append(f" 直播间原文:{room_title_raw or '-'}")
lines.append(f" 记录时间:{created_str}")
lines.append("-" * 40)
reservation_text.insert("1.0", "\n".join(lines))
else:
reservation_text.delete("1.0", "end")
reservation_text.insert("1.0", "暂无预约队列数据")