diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index ef3d99c..e22d1fa 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -10,10 +10,15 @@ from __future__ import annotations +from datetime import datetime from typing import Any, List, Tuple, Optional -import os -import time + +import json import logging +import os +import subprocess +import time +import traceback from Underlying_Operations import underlying_operations @@ -63,8 +68,6 @@ class fudai_analyse: # 日志相关字段:完全独立的日志系统(不依赖原始代码) try: - from datetime import datetime - self._run_id = datetime.now().strftime("%Y%m%d%H%M%S") except Exception: self._run_id = str(int(time.time())) @@ -273,6 +276,7 @@ class fudai_analyse: self._reservations_state_path: str = os.path.join( os.path.dirname(__file__), "state", "reservations.json" ) + self._reservations_state_last_write_ts: float = 0.0 # 运行时直播间标题和位置映射表(用于回退校验) # 格式:{room_pos: (room_title, room_title_raw)} @@ -490,8 +494,6 @@ class fudai_analyse: self.resolution_ratio_x, self.resolution_ratio_y = 1080, 2400 # 记录运行开始 - from datetime import datetime - start_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] try: actions_log_path = os.path.join( @@ -518,8 +520,6 @@ class fudai_analyse: "ERROR", "fudai_choujiang top-level exception", error=str(top_exc) ) except Exception: - import traceback - traceback.print_exc() raise @@ -1020,10 +1020,6 @@ class fudai_analyse: 注意:此方法复杂度较高,已通过模块化重构将部分逻辑拆分到子模块。 """ - from douyin.reservation import ( - douyin_reservation_logic, - ) # pylint: disable=redefined-outer-name - start_time = time.time() # 直接参与标志已移除,相关旧逻辑已清理,继续按正常流程执行 # 0. 如果正在等待开奖,检查高价值预约是否需要抢占,否则只检测开奖结果 @@ -1049,16 +1045,11 @@ class fudai_analyse: room_pos_ref[0], reservation_focus_until_ts_ref, reservation_after_action_pending_ref, - float( - getattr(self, "reservation_back_swipe_delay_s", 0.5) - or 0.5 - ), - lambda: self.swipe_down_back_from_live(), - lambda item: self._seek_reservation_room(item), + float(getattr(self, "reservation_back_swipe_delay_s", 0.5) or 0.5), + self.swipe_down_back_from_live, + self._seek_reservation_room, lambda: ( - douyin_reservation_logic._sort_reservations_inplace( - self.reservations - ) + douyin_reservation_logic._sort_reservations_inplace(self.reservations) if self.reservations else None ), @@ -1457,8 +1448,6 @@ class fudai_analyse: for idx, r in enumerate(reservations_list[:3]): # 只显示前3个 try: ft = float(r.get("future_ts") or 0) - from datetime import datetime - ft_str = ( datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") if ft > 0 @@ -1532,8 +1521,6 @@ class fudai_analyse: return self._reservations_state_last_write_ts = now_ts - import json - os.makedirs( os.path.dirname(self._reservations_state_path), exist_ok=True, @@ -1725,10 +1712,7 @@ class fudai_analyse: first_r = self.reservations[0] try: ft = float(first_r.get("future_ts") or 0) - from datetime import datetime - import time as time_module - - now_ts = time_module.time() + now_ts = time.time() ft_str = ( datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") if ft > 0 @@ -1850,10 +1834,6 @@ class fudai_analyse: pass try: - from douyin.reservation import ( - douyin_reservation_logic, - ) # pylint: disable=redefined-outer-name - douyin_reservation_logic.cleanup_expired_reservations( self, self.reservations, _write_state ) @@ -2501,8 +2481,8 @@ class fudai_analyse: and isinstance(detail, tuple) and len(detail) >= 6 ): - # 使用解包避免索引告警 - _, _, _, _, _, countdown_tuple = detail + # 直接获取倒计时字段,避免强制解包 + countdown_tuple = detail[5] if ( isinstance(countdown_tuple, (tuple, list)) and len(countdown_tuple) >= 2 @@ -2794,22 +2774,16 @@ class fudai_analyse: end_y = 700 * ry // 2400 # 直接使用 ADB 内部滑动命令 try: - import subprocess - if hasattr(self.operation, "_adb"): adb_cmd = self.operation._adb() else: - import os - adb_cmd = ( os.environ.get( "ADB_EXECUTABLE", "adb" ) or "adb" ) - if not adb_cmd.startswith( - '"' - ) and not adb_cmd.endswith('"'): + if not adb_cmd.startswith('"') and not adb_cmd.endswith('"'): adb_cmd = f'"{adb_cmd}"' cmd = f"{adb_cmd} -s {self.device_id} shell input swipe {start_x} {start_y} {end_x} {end_y} 300" subprocess.run( @@ -2818,6 +2792,7 @@ class fudai_analyse: timeout=5.0, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + check=True, ) except Exception: # 回退到 operation.swipe @@ -2975,13 +2950,9 @@ class fudai_analyse: end_y = 700 * ry // 2400 # 直接使用 ADB 内部滑动命令 try: - import subprocess - if hasattr(self.operation, "_adb"): adb_cmd = self.operation._adb() else: - import os - adb_cmd = ( os.environ.get( "ADB_EXECUTABLE", "adb" @@ -2999,6 +2970,7 @@ class fudai_analyse: timeout=5.0, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + check=True, ) except Exception: # 回退到 operation.swipe @@ -3199,10 +3171,6 @@ class fudai_analyse: # 从预约队列中移除已完成的预约(匹配 future_ts,允许5秒误差) if hasattr(self, "reservations") and self.reservations: - from douyin.reservation import ( - douyin_reservation_logic, - ) # pylint: disable=redefined-outer-name - reservations_to_remove = [] for idx, r in enumerate(self.reservations): try: @@ -3326,9 +3294,7 @@ class fudai_analyse: # 检查是否在锁定期内,且时间窗口未到,避免重复打开福袋详情 try: - import time as time_module - - now_ts = time_module.time() + now_ts = time.time() focus_until = float(getattr(self, "reservation_focus_until_ts", 0.0) or 0.0) queue_full_waiting = bool( getattr(self, "queue_full_waiting_at_earliest", False) or False diff --git a/douyin/core/state/reservations.json b/douyin/core/state/reservations.json index 70150cf..b911901 100644 --- a/douyin/core/state/reservations.json +++ b/douyin/core/state/reservations.json @@ -1,8 +1,23 @@ { - "updated_ts": 1767488733.548808, - "reason": "startup_clear", + "updated_ts": 1767489629.8950424, + "reason": "remove_reservation_after_attend", "room_pos": 0, - "current_room_title": "", + "current_room_title": "火烘", "current_room_title_raw": "", - "reservations": [] -} + "reservations": [ + { + "prize_value_yuan": 3499.0, + "content": "", + "future_ts": 1767490318.654792, + "future_str": "2026-01-04 09:31:58", + "pos_seen": 3, + "room_title": "带娃的小", + "room_title_raw": "带娃的小.", + "created_ts": 1767489560.8793976, + "task_count": 2, + "time_text": "12:43", + "participants": 0, + "copies": 0 + } + ] +} \ No newline at end of file diff --git a/gui/gui_core.py b/gui/gui_core.py index 72e82ee..399e12b 100644 --- a/gui/gui_core.py +++ b/gui/gui_core.py @@ -126,6 +126,10 @@ class Runner: self._events_cap: int = 5000 self._wins: list[dict] = [] self._wins_cap: int = 200 + # 唯一计数去重集合(用于展示“唯一成功次数”口径) + self._unique_keys_seen: set[str] = set() + self._unique_keys_open: set[str] = set() + self._unique_keys_attend: set[str] = set() def is_running(self) -> bool: return self._proc is not None and self._proc.poll() is None @@ -145,6 +149,21 @@ class Runner: if len(self._events) > self._events_cap: self._events = self._events[-self._events_cap :] + def _make_unique_key(self) -> str: + """根据当前 snapshot 生成一个尽可能稳定的唯一键(用于去重)。 + + 使用 content/prize_value/countdown 三元组,如果不可用则返回空字符串。 + """ + try: + with self._lock: + content = (self._fudai_last.get("content") or "") + prize = str(self._fudai_last.get("prize_value_yuan") or "") + countdown = str(self._fudai_last.get("countdown") or "") + key = f"{content}|{prize}|{countdown}" + return key + except Exception: + return "" + def _record_win(self) -> None: item = { "ts": time.time(),