Files
douyin_guaji-main/douyin_lottery.py
T
Your Name 836a31d817 refactor: Remove outdated files and enhance Web GUI functionality
- Deleted obsolete markdown files related to follow tab coordinates testing and results.
- Removed outdated batch scripts for launching the Web GUI.
- Updated `config.json` to improve reservation handling and adjust prize value settings.
- Enhanced logging and error handling in `web_gui.py` and `app.js` for better user experience.
- Added automatic screenshot functionality during Web GUI startup for improved monitoring.
2025-12-19 03:31:08 +08:00

180 lines
5.4 KiB
Python

from __future__ import annotations
"""
Lottery helpers shim (WebGUI version)
=====================================
Exports:
- wait_for_lottery_result
- process_lottery_result
"""
from typing import Any, Dict, Tuple
import time
def wait_for_lottery_result(
analyser: Any,
lastsecond: int,
future_timestamp: float,
reservation_after_action_pending: bool,
reservation_should_preempt_callback,
) -> Tuple[bool, int, float | None, int | None]:
"""兼容实现:按原始签名等待开奖,当前版本只做时间等待与简单抢占判断。"""
start = time.time()
# 简单轮询等待一小段时间,保留结构但不做重型逻辑
detect_attempts = 0
first_detect_ts: float | None = None
initial_check_result: int | None = None
# 最多等待 min(倒计时+5, 15) 秒,避免阻塞过久
total_wait_s = max(0.0, float(lastsecond or 0) + 5.0)
total_wait_s = min(total_wait_s, 15.0)
step_s = 1.5
while (time.time() - start) < total_wait_s:
detect_attempts += 1
if first_detect_ts is None:
first_detect_ts = time.time()
# 若有"预约应抢占"回调,则在等待期间尊重其判断
try:
if reservation_should_preempt_callback is not None and reservation_should_preempt_callback():
return True, detect_attempts, first_detect_ts, initial_check_result or 0
except Exception:
pass
try:
analyser.operation.delay(step_s)
except Exception:
time.sleep(step_s)
# 占位返回:未被预约抢占,未检测到明确结果
return False, detect_attempts, first_detect_ts, initial_check_result
def process_lottery_result(
analyser: Any,
x: int,
t_participate: float,
detect_attempts: int,
first_detect_ts: float | None,
initial_check_result: int | None,
reservation_focus_until_ts: float,
reservation_focus_until_ts_ref: list,
reservation_after_action_pending_ref: list,
needswitch: bool,
post_switch_delay_s: float,
swipe_up_switch_callback,
clear_reservations_callback,
get_recommend_seconds_callback,
yanghao_wait_callback,
) -> bool:
"""兼容实现:记录开奖阶段的调试信息,当前版本不修改预约/房间状态。"""
try:
analyser._log_kv(
"开奖",
"process_lottery_result",
x=x,
detect_attempts=detect_attempts,
first_detect_ts=first_detect_ts,
initial_check_result=initial_check_result,
)
except Exception:
pass
return False
"""
Lottery helpers shim (WebGUI version)
=====================================
Exports:
- wait_for_lottery_result
- process_lottery_result
"""
from typing import Any, Dict, Tuple
import time
def wait_for_lottery_result(
analyser: Any,
lastsecond: int,
future_timestamp: float,
reservation_after_action_pending: bool,
reservation_should_preempt_callback,
) -> Tuple[bool, int, float | None, int | None]:
"""Shim version matching original signature.
为了安全起见,这里不做真实的开奖结果 OCR,仅按时间简单等待并返回
“未被预约抢占、未检测到结果”的占位信息,避免打断主流程。
"""
start = time.time()
# 简单轮询等待一小段时间,保留结构但不做重型逻辑
detect_attempts = 0
first_detect_ts: float | None = None
initial_check_result: int | None = None
# 最多等待 min(倒计时+5, 15) 秒,避免阻塞过久
total_wait_s = max(0.0, float(lastsecond or 0) + 5.0)
total_wait_s = min(total_wait_s, 15.0)
step_s = 1.5
while (time.time() - start) < total_wait_s:
detect_attempts += 1
if first_detect_ts is None:
first_detect_ts = time.time()
# 若有"预约应抢占"回调,则在等待期间尊重其判断
try:
if reservation_should_preempt_callback is not None and reservation_should_preempt_callback():
return True, detect_attempts, first_detect_ts, initial_check_result or 0
except Exception:
pass
try:
analyser.operation.delay(step_s)
except Exception:
time.sleep(step_s)
# 占位返回:未被预约抢占,未检测到明确结果
return False, detect_attempts, first_detect_ts, initial_check_result
def process_lottery_result(
analyser: Any,
x: int,
t_participate: float,
detect_attempts: int,
first_detect_ts: float | None,
initial_check_result: int | None,
reservation_focus_until_ts: float,
reservation_focus_until_ts_ref: list,
reservation_after_action_pending_ref: list,
needswitch: bool,
post_switch_delay_s: float,
swipe_up_switch_callback,
clear_reservations_callback,
get_recommend_seconds_callback,
yanghao_wait_callback,
) -> bool:
"""Shim: match original signature and record basic diagnostics.
为了安全起见,这里不再做复杂的开奖 OCR/状态机,仅:
- 记录一次日志方便事后分析;
- 不修改预约/房间状态;
- 始终返回 False(表示不主动中断主循环)。
"""
try:
analyser._log_kv(
"开奖",
"process_lottery_result",
x=x,
detect_attempts=detect_attempts,
first_detect_ts=first_detect_ts,
initial_check_result=initial_check_result,
)
except Exception:
pass
return False