feat: 优化代码格式,提升可读性和一致性
This commit is contained in:
1 parent
3488624b8f
commit
ca3b2f6fea
4 files changed
+62
-33
No files matched your search
@@ -2089,9 +2089,8 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
or str(getattr(analyser, "current_room_title_raw", "") or "")
|
||||
)
|
||||
|
||||
button_text_for_map = (
|
||||
str(button_text_raw or "")
|
||||
or str(getattr(analyser, "button_text_raw", "") or "")
|
||||
button_text_for_map = str(button_text_raw or "") or str(
|
||||
getattr(analyser, "button_text_raw", "") or ""
|
||||
)
|
||||
|
||||
room_info = dict(base_info)
|
||||
|
||||
@@ -1042,23 +1042,33 @@ def _dump_room_pos_map_to_state(analyser: Any) -> None:
|
||||
final_path = os.path.join(state_dir, "room_pos_map.json")
|
||||
tmp_path = final_path + ".tmp"
|
||||
|
||||
# 过滤掉空条目,只保留本次运行有值的映射
|
||||
# 过滤并保留映射:
|
||||
# - 对于 dict 条目(新格式),保留完整 dict(以便包含 fudai_detail 等字段)
|
||||
# - 对于旧格式 list/tuple,保持原有行为(写入 [title, title_raw])
|
||||
# 条件:如果条目没有标题/原始标题且也不包含福袋信息,则跳过
|
||||
filtered = {}
|
||||
for k, v in room_pos_map.items():
|
||||
try:
|
||||
if isinstance(v, dict):
|
||||
title = (v.get("title", "") or "").strip()
|
||||
title_raw = (v.get("title_raw", "") or "").strip()
|
||||
has_fudai = bool(v.get("has_fudai", False))
|
||||
fudai_detail = v.get("fudai_detail")
|
||||
# 如果既没有标题也没有福袋信息,则跳过
|
||||
if not title and not title_raw and not has_fudai and not fudai_detail:
|
||||
continue
|
||||
# 保留完整 dict,便于 GUI 读取更多字段
|
||||
filtered[str(k)] = v
|
||||
else:
|
||||
# 兼容旧格式
|
||||
# 兼容旧格式:仍然写入 [title, title_raw]
|
||||
title = (v[0] or "").strip() if len(v) > 0 else ""
|
||||
title_raw = (v[1] or "").strip() if len(v) > 1 else ""
|
||||
if not title and not title_raw:
|
||||
continue
|
||||
filtered[str(k)] = [title, title_raw]
|
||||
except Exception:
|
||||
title = ""
|
||||
title_raw = ""
|
||||
if not title and not title_raw:
|
||||
# 忽略单条处理错误,继续下一个
|
||||
continue
|
||||
filtered[str(k)] = [title, title_raw]
|
||||
|
||||
# 准备写入数据:保留原有 top-level 映射结构,同时添加一个保留的元信息字段
|
||||
data = dict(filtered)
|
||||
|
||||
@@ -1885,8 +1885,13 @@ def process_reservation_attend_window(
|
||||
target_room_title_raw,
|
||||
)
|
||||
)
|
||||
if mapped_target_pos is not None and mapped_target_pos > 0:
|
||||
updated_target["pos_seen"] = int(mapped_target_pos)
|
||||
if (
|
||||
mapped_target_pos is not None
|
||||
and mapped_target_pos > 0
|
||||
):
|
||||
updated_target["pos_seen"] = int(
|
||||
mapped_target_pos
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
@@ -1920,12 +1925,17 @@ def process_reservation_attend_window(
|
||||
|
||||
# 识别当前直播间标题(优先缓存,必要时重新识别)
|
||||
current_room_title = str(
|
||||
getattr(analyser, "current_room_title", "") or ""
|
||||
getattr(analyser, "current_room_title", "")
|
||||
or ""
|
||||
).strip()
|
||||
current_room_title_raw = str(
|
||||
getattr(analyser, "current_room_title_raw", "") or ""
|
||||
getattr(analyser, "current_room_title_raw", "")
|
||||
or ""
|
||||
).strip()
|
||||
if not current_room_title and not current_room_title_raw:
|
||||
if (
|
||||
not current_room_title
|
||||
and not current_room_title_raw
|
||||
):
|
||||
try:
|
||||
from douyin.fudai import douyin_fudai_detail
|
||||
|
||||
@@ -1935,10 +1945,8 @@ def process_reservation_attend_window(
|
||||
(
|
||||
current_room_title,
|
||||
current_room_title_raw,
|
||||
) = (
|
||||
douyin_fudai_detail.read_live_room_title_core(
|
||||
analyser, y_pianyi_val
|
||||
)
|
||||
) = douyin_fudai_detail.read_live_room_title_core(
|
||||
analyser, y_pianyi_val
|
||||
)
|
||||
try:
|
||||
analyser.current_room_title = (
|
||||
@@ -1967,12 +1975,15 @@ def process_reservation_attend_window(
|
||||
):
|
||||
try:
|
||||
old_room_pos = int(
|
||||
getattr(analyser, "room_pos", 0) or 0
|
||||
getattr(analyser, "room_pos", 0)
|
||||
or 0
|
||||
)
|
||||
except Exception:
|
||||
old_room_pos = 0
|
||||
try:
|
||||
analyser.room_pos = int(mapped_current_pos)
|
||||
analyser.room_pos = int(
|
||||
mapped_current_pos
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
@@ -2034,8 +2045,12 @@ def process_reservation_attend_window(
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 映射表显示已在目标位置,但校验失败,跳过二次回退",
|
||||
mapped_current_pos=int(mapped_current_pos),
|
||||
mapped_target_pos=int(mapped_target_pos),
|
||||
mapped_current_pos=int(
|
||||
mapped_current_pos
|
||||
),
|
||||
mapped_target_pos=int(
|
||||
mapped_target_pos
|
||||
),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
+16
-11
@@ -2759,9 +2759,7 @@ def main():
|
||||
notebook.add(win_record_tab, text="中奖记录")
|
||||
# 将运行时映射表加入右侧 Notebook
|
||||
mapping_tab = ttk.Frame(notebook)
|
||||
map_box = ttk.LabelFrame(
|
||||
mapping_tab, text="运行时映射表(包含福袋详情)"
|
||||
)
|
||||
map_box = ttk.LabelFrame(mapping_tab, text="运行时映射表(包含福袋详情)")
|
||||
map_box.pack(fill=X, padx=10, pady=(10, 10))
|
||||
|
||||
map_ctrl = ttk.Frame(map_box)
|
||||
@@ -2965,18 +2963,21 @@ def main():
|
||||
countdown_text = "-"
|
||||
if isinstance(fudai_detail, dict):
|
||||
task_list = (
|
||||
str(fudai_detail.get("task_list") or "")
|
||||
.strip()
|
||||
str(
|
||||
fudai_detail.get("task_list") or ""
|
||||
).strip()
|
||||
or "-"
|
||||
)
|
||||
button_text = (
|
||||
str(fudai_detail.get("button_text") or "")
|
||||
.strip()
|
||||
str(
|
||||
fudai_detail.get("button_text") or ""
|
||||
).strip()
|
||||
or "-"
|
||||
)
|
||||
fudai_time = (
|
||||
str(fudai_detail.get("time_text") or "")
|
||||
.strip()
|
||||
str(
|
||||
fudai_detail.get("time_text") or ""
|
||||
).strip()
|
||||
or "-"
|
||||
)
|
||||
fudai_value = (
|
||||
@@ -2994,8 +2995,12 @@ def main():
|
||||
if fudai_detail.get("copies")
|
||||
else "-"
|
||||
)
|
||||
mm = str(fudai_detail.get("countdown_mm") or "").strip()
|
||||
ss = str(fudai_detail.get("countdown_ss") or "").strip()
|
||||
mm = str(
|
||||
fudai_detail.get("countdown_mm") or ""
|
||||
).strip()
|
||||
ss = str(
|
||||
fudai_detail.get("countdown_ss") or ""
|
||||
).strip()
|
||||
if fudai_time and fudai_time != "-":
|
||||
countdown_text = fudai_time
|
||||
elif mm or ss:
|
||||
|
||||
Reference in new issue
Block a user