feat: 优化函数调用安全性,确保实时查看功能的稳定性
This commit is contained in:
1 parent
b215e79a26
commit
0b50017c25
4 files changed
+79
-71
No files matched your search
+1
-1
@@ -191,4 +191,4 @@
|
||||
"enable_streaming_screenshot": false,
|
||||
"fudai_exit_after_misses": 30,
|
||||
"yanghao_only": false
|
||||
}
|
||||
}
|
||||
+48
-27
@@ -2484,25 +2484,24 @@ class fudai_analyse:
|
||||
ensure_open_callback=douyin_fudai_detail.ensure_fudai_detail_open,
|
||||
)
|
||||
# 重新读取后,更新保存的详情数据
|
||||
if detail and isinstance(detail, tuple) and len(detail) >= 6:
|
||||
self._last_fudai_detail_tuple = detail
|
||||
safe_detail = tuple(detail) if isinstance(detail, (list, tuple)) and len(detail) >= 6 else None
|
||||
if safe_detail:
|
||||
# 保持存储为 tuple,避免后续可变性导致问题
|
||||
try:
|
||||
self._last_fudai_detail_tuple = tuple(safe_detail)
|
||||
except Exception:
|
||||
self._last_fudai_detail_tuple = safe_detail
|
||||
else:
|
||||
# 使用第一次保存的详情数据,设置当前福袋的倒计时信息
|
||||
try:
|
||||
# 从保存的 tuple 中安全读取倒计时信息,使用 cast 明确类型以帮助静态分析
|
||||
detail = getattr(self, "_last_fudai_detail_tuple", None)
|
||||
if (
|
||||
detail is not None
|
||||
and isinstance(detail, tuple)
|
||||
and len(detail) >= 6
|
||||
):
|
||||
# 确认 detail 为序列后再索引,避免静态分析误报
|
||||
if isinstance(detail, (list, tuple)):
|
||||
try:
|
||||
countdown_tuple = detail[5]
|
||||
except Exception:
|
||||
countdown_tuple = ()
|
||||
else:
|
||||
safe_detail = tuple(detail) if isinstance(detail, (list, tuple)) and len(detail) >= 6 else None
|
||||
if safe_detail:
|
||||
# 确认 safe_detail 为序列后再索引,避免静态分析误报
|
||||
try:
|
||||
countdown_tuple = safe_detail[5]
|
||||
except Exception:
|
||||
countdown_tuple = ()
|
||||
if (
|
||||
isinstance(countdown_tuple, (tuple, list))
|
||||
@@ -2575,12 +2574,15 @@ class fudai_analyse:
|
||||
|
||||
# 在第一次打开时立即进行筛选检查,如果不符合要求则直接跳过
|
||||
# 注意:这里只检查筛选条件,不执行参与操作
|
||||
if detail and isinstance(detail, tuple) and len(detail) >= 6:
|
||||
# 为了避免静态分析将 `detail` 视为不可下标对象,先构造一个
|
||||
# 明确为序列的本地变量 `safe_detail`(类型为 tuple),后续所有索引/解包均使用它。
|
||||
safe_detail: Optional[Tuple[Any, ...]] = tuple(detail) if isinstance(detail, (list, tuple)) and len(detail) >= 6 else None
|
||||
if safe_detail:
|
||||
# 先进行数据验证
|
||||
is_valid = True
|
||||
try:
|
||||
is_valid, reason = douyin_fudai_detail.validate_fudai_detail(
|
||||
detail, self
|
||||
safe_detail, self
|
||||
)
|
||||
if not is_valid:
|
||||
try:
|
||||
@@ -2617,9 +2619,16 @@ class fudai_analyse:
|
||||
# 提取价值信息
|
||||
prize_value_yuan = 0.0
|
||||
countdown_tuple = None
|
||||
if isinstance(detail, tuple) and len(detail) >= 6:
|
||||
# 使用解包避免索引告警
|
||||
_, _, _, _, prize_value_yuan, countdown_tuple = detail
|
||||
if safe_detail:
|
||||
# 使用明确的序列类型以帮助静态分析和避免不可下标告警
|
||||
try:
|
||||
prize_value_yuan = float(safe_detail[4] or 0.0)
|
||||
except Exception:
|
||||
prize_value_yuan = 0.0
|
||||
try:
|
||||
countdown_tuple = safe_detail[5]
|
||||
except Exception:
|
||||
countdown_tuple = None
|
||||
|
||||
# 检查是否启用高价值预约
|
||||
high_value_enabled = bool(
|
||||
@@ -3081,9 +3090,13 @@ class fudai_analyse:
|
||||
|
||||
# 兜底检查:如果价值为0且内容为空,也可能是优惠券弹窗或识别错误
|
||||
try:
|
||||
if isinstance(detail, tuple) and len(detail) >= 5:
|
||||
content = str(detail[0] or "")
|
||||
prize_value_yuan = float(detail[4] or 0.0)
|
||||
safe_detail = detail if isinstance(detail, (list, tuple)) and len(detail) >= 5 else None
|
||||
if safe_detail:
|
||||
content = str(safe_detail[0] or "")
|
||||
try:
|
||||
prize_value_yuan = float(safe_detail[4] or 0.0)
|
||||
except Exception:
|
||||
prize_value_yuan = 0.0
|
||||
if not content and prize_value_yuan == 0.0:
|
||||
try:
|
||||
self._log_kv(
|
||||
@@ -3109,8 +3122,12 @@ class fudai_analyse:
|
||||
|
||||
# 记录当前福袋的 future_ts,供 attend_choujiang 使用
|
||||
try:
|
||||
if isinstance(detail, tuple) and len(detail) >= 6:
|
||||
countdown_tuple = detail[5]
|
||||
safe_detail = detail if isinstance(detail, (list, tuple)) and len(detail) >= 6 else None
|
||||
if safe_detail:
|
||||
try:
|
||||
countdown_tuple = safe_detail[5]
|
||||
except Exception:
|
||||
countdown_tuple = None
|
||||
if (
|
||||
isinstance(countdown_tuple, (tuple, list))
|
||||
and len(countdown_tuple) >= 2
|
||||
@@ -3151,9 +3168,13 @@ class fudai_analyse:
|
||||
countdown_tuple = None
|
||||
remain_seconds = 0
|
||||
future_timestamp = 0.0
|
||||
if isinstance(detail, tuple) and len(detail) >= 6:
|
||||
countdown_tuple = detail[5]
|
||||
if isinstance(countdown_tuple, tuple) and len(countdown_tuple) >= 2:
|
||||
safe_detail = detail if isinstance(detail, (list, tuple)) and len(detail) >= 6 else None
|
||||
if safe_detail:
|
||||
try:
|
||||
countdown_tuple = safe_detail[5]
|
||||
except Exception:
|
||||
countdown_tuple = None
|
||||
if isinstance(countdown_tuple, (tuple, list)) and len(countdown_tuple) >= 2:
|
||||
# countdown_tuple[0] 是 countdown_start(开始时间戳)
|
||||
# countdown_tuple[1] 是 countdown_end(结束时间戳/开奖时间戳)
|
||||
future_timestamp = float(countdown_tuple[1] or 0.0)
|
||||
|
||||
@@ -1,49 +1,21 @@
|
||||
{
|
||||
"updated_ts": 1767491537.0721958,
|
||||
"updated_ts": 1767492808.7388206,
|
||||
"reason": "record_reservation",
|
||||
"room_pos": 3,
|
||||
"current_room_title": "带娃的小",
|
||||
"current_room_title_raw": "带娃的小.",
|
||||
"room_pos": 0,
|
||||
"current_room_title": "彩虹夫妇",
|
||||
"current_room_title_raw": "彩虹夫妇",
|
||||
"reservations": [
|
||||
{
|
||||
"prize_value_yuan": 699.0,
|
||||
"prize_value_yuan": 6999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767491839.675532,
|
||||
"future_str": "2026-01-04 09:57:19",
|
||||
"pos_seen": 3,
|
||||
"room_title": "带娃的小",
|
||||
"room_title_raw": "带娃的小.",
|
||||
"created_ts": 1767491462.9488251,
|
||||
"task_count": 2,
|
||||
"time_text": "06:22",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
},
|
||||
{
|
||||
"prize_value_yuan": 1999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767492193.581507,
|
||||
"future_str": "2026-01-04 10:03:13",
|
||||
"future_ts": 1767493214.565064,
|
||||
"future_str": "2026-01-04 10:20:14",
|
||||
"pos_seen": 0,
|
||||
"room_title": "作川帮数",
|
||||
"room_title_raw": "作川帮数。。",
|
||||
"created_ts": 1767491317.7698174,
|
||||
"room_title": "彩虹夫妇",
|
||||
"room_title_raw": "彩虹夫妇",
|
||||
"created_ts": 1767492808.7325442,
|
||||
"task_count": 2,
|
||||
"time_text": "14:41",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
},
|
||||
{
|
||||
"prize_value_yuan": 1999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767492193.641006,
|
||||
"future_str": "2026-01-04 10:03:13",
|
||||
"pos_seen": 0,
|
||||
"room_title": "作帮粼",
|
||||
"room_title_raw": "作!帮粼。。",
|
||||
"created_ts": 1767491385.7829947,
|
||||
"task_count": 2,
|
||||
"time_text": "13:33",
|
||||
"time_text": "06:51",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
}
|
||||
|
||||
+19
-4
@@ -2237,7 +2237,11 @@ def main():
|
||||
realtime_tools,
|
||||
text="实时查看",
|
||||
width=10,
|
||||
command=lambda: _open_realtime_viewer_impl() if callable(_open_realtime_viewer_impl) else None,
|
||||
command=lambda: (
|
||||
_open_realtime_viewer_impl()
|
||||
if callable(_open_realtime_viewer_impl)
|
||||
else None
|
||||
),
|
||||
).pack(side=LEFT, padx=(8, 0))
|
||||
|
||||
log_tab = ttk.Frame(notebook)
|
||||
@@ -2428,7 +2432,10 @@ def main():
|
||||
def _open_realtime_viewer_impl():
|
||||
try:
|
||||
# 如果已打开则直接聚焦
|
||||
if hasattr(_open_realtime_viewer_impl, "_win") and _open_realtime_viewer_impl._win:
|
||||
if (
|
||||
hasattr(_open_realtime_viewer_impl, "_win")
|
||||
and _open_realtime_viewer_impl._win
|
||||
):
|
||||
try:
|
||||
_open_realtime_viewer_impl._win.lift()
|
||||
except Exception:
|
||||
@@ -3230,7 +3237,9 @@ def main():
|
||||
click_rate = (fudai_click_attend / fudai_open_detail) * 100
|
||||
lines.append(f" 点击率: {click_rate:.1f}%")
|
||||
|
||||
lines.append(f"参与成功: {fudai_attend_ok} (唯一次数: {fudai_attend_ok_unique})")
|
||||
lines.append(
|
||||
f"参与成功: {fudai_attend_ok} (唯一次数: {fudai_attend_ok_unique})"
|
||||
)
|
||||
lines.append(f"参与失败: {fudai_attend_fail}")
|
||||
# 参与成功率应该基于点击参与次数来计算
|
||||
# 因为参与成功可能包括"检测到已参与"的情况(没有点击)
|
||||
@@ -4663,7 +4672,13 @@ def main():
|
||||
ttk.Button(
|
||||
win_record_top,
|
||||
text="实时查看",
|
||||
command=(lambda: _open_realtime_viewer_impl() if callable(_open_realtime_viewer_impl) else None),
|
||||
command=(
|
||||
lambda: (
|
||||
_open_realtime_viewer_impl()
|
||||
if callable(_open_realtime_viewer_impl)
|
||||
else None
|
||||
)
|
||||
),
|
||||
).pack(side=LEFT, padx=(8, 0))
|
||||
|
||||
# 误识别记录管理
|
||||
|
||||
Reference in new issue
Block a user