From ca3b2f6fea55807c91542fc7208cbb611c2b0949 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 17 Jan 2026 19:14:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=8C=E6=8F=90=E5=8D=87=E5=8F=AF=E8=AF=BB?= =?UTF-8?q?=E6=80=A7=E5=92=8C=E4=B8=80=E8=87=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin/fudai/douyin_fudai_core.py | 5 +-- .../reservation/douyin_reservation_handler.py | 22 +++++++--- .../reservation/douyin_reservation_logic.py | 41 +++++++++++++------ gui/gui_app.py | 27 +++++++----- 4 files changed, 62 insertions(+), 33 deletions(-) diff --git a/douyin/fudai/douyin_fudai_core.py b/douyin/fudai/douyin_fudai_core.py index 3fb2dd8..135f470 100644 --- a/douyin/fudai/douyin_fudai_core.py +++ b/douyin/fudai/douyin_fudai_core.py @@ -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) diff --git a/douyin/reservation/douyin_reservation_handler.py b/douyin/reservation/douyin_reservation_handler.py index c19fc67..ed247ba 100644 --- a/douyin/reservation/douyin_reservation_handler.py +++ b/douyin/reservation/douyin_reservation_handler.py @@ -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) diff --git a/douyin/reservation/douyin_reservation_logic.py b/douyin/reservation/douyin_reservation_logic.py index 9d2f4ad..ea07b84 100644 --- a/douyin/reservation/douyin_reservation_logic.py +++ b/douyin/reservation/douyin_reservation_logic.py @@ -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 diff --git a/gui/gui_app.py b/gui/gui_app.py index 238d780..cf678c7 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -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: