fix: Clean up blank lines and enhance readability across multiple files

- Removed excessive blank lines from various markdown and Python files to improve readability and maintainability.
- Ensured consistent formatting across documentation and code files, contributing to overall project clarity.
- Updated logging mechanisms for better consistency and debugging support.
This commit is contained in:
Your Name committed 2025-12-27 17:10:19 +08:00
1 parent efaa3d3adc
commit ea7159355b
32 files changed
+360 -62

No files matched your search

+2
View File
@@ -194,6 +194,8 @@ python cleanup_unused_files.py
+2
View File
@@ -205,6 +205,8 @@ except Exception as e:
+2
View File
@@ -408,6 +408,8 @@ self.last_fudai_x: int = 0 # 上次检测到的福袋图标X坐标
+2
View File
@@ -292,6 +292,8 @@ YYYYMMDD_HHMMSS_操作类型_图片名_步骤_坐标_额外信息.png
+2
View File
@@ -263,6 +263,8 @@ python check_dependencies.py
+2
View File
@@ -242,6 +242,8 @@ douyin_guaji
+2
View File
@@ -183,6 +183,8 @@
+2
View File
@@ -395,6 +395,8 @@ douyin_fudai_finder.py
+2
View File
@@ -194,6 +194,8 @@ self.ocr = easyocr.Reader(
+2
View File
@@ -153,6 +153,8 @@ python 生成WPS流程图.py
+2
View File
@@ -167,6 +167,8 @@ else:
+58 -6
View File
@@ -158,13 +158,67 @@ def find_and_open_fudai_detail(
# 优先走底层 operation.click,失败再尝试 analyser.click
try:
analyser.operation.click(device_id, click_x, click_y)
# 点击后等待福袋详情页加载(可配置)
fudai_click_wait_seconds = float(
# 智能等待:先等待最小时间,然后循环检测详情页是否已打开
# 这样可以减少不必要的等待时间
min_wait_seconds = 0.5 # 最小等待时间(确保点击生效)
max_wait_seconds = float(
getattr(analyser, "fudai_click_wait_seconds", 2.0) or 2.0
)
analyser.operation.delay(fudai_click_wait_seconds)
check_interval = 0.2 # 每次检测间隔(秒)
# 先等待最小时间
analyser.operation.delay(min_wait_seconds)
# 智能等待:循环检测详情页是否已打开
import douyin_stage
wait_start = time.time()
detail_opened = False
while (time.time() - wait_start) < (max_wait_seconds - min_wait_seconds):
try:
analyser.operation.get_screenshot(device_id)
pic_path = path_config.get_screenshot_path()
if os.path.exists(pic_path):
# 快速检测是否已在详情页(只检测关键特征,不执行完整阶段诊断)
result = douyin_stage.diagnose_stage_from_current_screen(analyser)
if result is not None:
stage, _ = result
if stage == "FUDai_DETAIL":
detail_opened = True
elapsed_wait = time.time() - wait_start
try:
analyser._log_kv(
"流程",
"find_and_open_fudai_detail:智能等待检测到详情页已打开",
wait_seconds=round(elapsed_wait + min_wait_seconds, 2),
)
except Exception:
pass
break
except Exception:
pass
# 等待一小段时间后再次检测
try:
analyser.operation.delay(check_interval)
except Exception:
time.sleep(check_interval)
# 如果智能等待已检测到详情页,直接返回成功,无需再次检测
if detail_opened:
# 清除第一次读取标志,确保新打开的福袋会进行完整的OCR识别
try:
analyser._fudai_detail_first_read = False
analyser._last_fudai_detail_tuple = None
except Exception:
pass
elapsed = time.time() - func_start_time
analyser._log_kv("流程", "find_and_open_fudai_detail完成(成功打开详情)", elapsed_seconds=round(elapsed, 2))
return True
# 点击后验证:检测是否成功打开福袋详情页(必须执行,不能静默失败)
# 如果智能等待未检测到详情页,执行完整的验证流程
# 确保有最新截图
analyser.operation.get_screenshot(device_id)
pic_path = path_config.get_screenshot_path()
if not os.path.exists(pic_path):
@@ -179,8 +233,6 @@ def find_and_open_fudai_detail(
# 点击后进行阶段检测,确认当前页面状态
try:
import douyin_stage
result = douyin_stage.diagnose_stage_from_current_screen(analyser)
if result is None:
stage, reason = ("IN_LIVE_ROOM", "阶段诊断返回 None,默认判定为在直播间")
+148 -24
View File
@@ -143,6 +143,8 @@ class fudai_analyse:
self.fudai_click_wait_seconds: float = 2.0
# 切换直播间后等待阶段诊断的时间(秒)
self.switch_room_wait_after_stage_diag_seconds: float = 7.0
# 滑动速度(毫秒),影响滑动持续时间,值越大滑动越慢
self.swipe_duration_ms: int = 600
# fudai_find_max_attempts 已废弃,保留仅为兼容性,实际不再使用
self.fudai_find_max_attempts: int = 10
@@ -494,6 +496,10 @@ class fudai_analyse:
"switch_room_wait_after_stage_diag_seconds",
self.switch_room_wait_after_stage_diag_seconds,
)
self.swipe_duration_ms = _int(
"swipe_duration_ms",
self.swipe_duration_ms,
)
self.fudai_find_max_attempts = _int(
"fudai_find_max_attempts",
self.fudai_find_max_attempts,
@@ -2571,6 +2577,7 @@ class fudai_analyse:
except Exception:
pass
# 查找福袋并打开详情页
import douyin_flow_control
room_pos_ref = [int(getattr(self, "room_pos", 0) or 0)]
original_max_wait = getattr(self, "fudai_icon_max_wait_seconds", None)
try:
@@ -3162,21 +3169,61 @@ class fudai_analyse:
except Exception:
pass
if reservation_direct_attend:
# 预约回退后直接参与:使用正常流程,但设置强制参与标志
# 先检查预约是否过期
expired = False
try:
self._reservation_back_direct_attend = False # 清除标志
# 设置强制参与标志,让 basic_join_decision 跳过倒计时检查
self._force_attend_after_reservation_back = True
self._log_kv(
"预约",
"[预约] 预约回退后直接参与:使用正常流程,设置强制参与标志",
flag_cleared=True,
force_attend=True,
)
if self.reservations and len(self.reservations) > 0:
first_reservation = self.reservations[0]
future_ts = float(first_reservation.get("future_ts", 0.0) or 0.0)
if future_ts > 0:
now_ts = time.time()
poll_before = float(getattr(self, "high_value_fudai_poll_before_seconds", 10.0) or 10.0)
expired_threshold = future_ts + max(0.0, poll_before)
if now_ts > expired_threshold:
expired = True
from datetime import datetime
future_str = datetime.fromtimestamp(future_ts).strftime("%Y-%m-%d %H:%M:%S") if future_ts > 0 else "无效"
expired_seconds = int(now_ts - expired_threshold)
self._log_kv(
"预约",
"[预约] 预约回退后直接参与:福袋已过期,清除标志",
future_ts=int(future_ts),
future_str=future_str,
expired_seconds=expired_seconds,
)
# 清除相关标志
self._reservation_back_direct_attend = False
self._force_attend_after_reservation_back = False
self.queue_full_waiting_at_earliest = False
# 清理过期预约
import douyin_reservation_logic
douyin_reservation_logic.cleanup_expired_reservations(
analyser=self,
reservations=self.reservations,
write_state_callback=lambda: None,
)
except Exception:
pass
# 使用正常流程处理
self._handle_reservation_direct_attend()
if not expired:
# 预约回退后直接参与:使用正常流程,但设置强制参与标志
try:
self._reservation_back_direct_attend = False # 清除标志
# 设置强制参与标志,让 basic_join_decision 跳过倒计时检查
self._force_attend_after_reservation_back = True
self._log_kv(
"预约",
"[预约] 预约回退后直接参与:使用正常流程,设置强制参与标志",
flag_cleared=True,
force_attend=True,
)
except Exception:
pass
# 使用正常流程处理
self._handle_reservation_direct_attend()
else:
# 已过期,执行正常流程
self._handle_in_fudai_detail()
elapsed = time.time() - start_time
self._log_kv(
"流程",
@@ -3213,20 +3260,57 @@ class fudai_analyse:
except Exception:
pass
if reservation_direct_attend:
# 预约回退后直接参与:查找福袋并打开详情页,然后直接参与
# 先检查预约是否过期
expired = False
try:
self._reservation_back_direct_attend = False # 清除标志
# 设置强制参与标志,让 basic_join_decision 跳过倒计时检查
self._force_attend_after_reservation_back = True
self._log_kv(
"预约",
"[预约] 预约回退后直接参与:查找福袋并打开详情页,设置强制参与标志",
flag_cleared=True,
force_attend=True,
stage=stage,
)
if self.reservations and len(self.reservations) > 0:
first_reservation = self.reservations[0]
future_ts = float(first_reservation.get("future_ts", 0.0) or 0.0)
if future_ts > 0:
now_ts = time.time()
poll_before = float(getattr(self, "high_value_fudai_poll_before_seconds", 10.0) or 10.0)
expired_threshold = future_ts + max(0.0, poll_before)
if now_ts > expired_threshold:
expired = True
from datetime import datetime
future_str = datetime.fromtimestamp(future_ts).strftime("%Y-%m-%d %H:%M:%S") if future_ts > 0 else "无效"
expired_seconds = int(now_ts - expired_threshold)
self._log_kv(
"预约",
"[预约] 预约回退后直接参与:福袋已过期,清除标志",
future_ts=int(future_ts),
future_str=future_str,
expired_seconds=expired_seconds,
)
# 清除相关标志
self._reservation_back_direct_attend = False
self._force_attend_after_reservation_back = False
self.queue_full_waiting_at_earliest = False
# 清理过期预约
import douyin_reservation_logic
douyin_reservation_logic.cleanup_expired_reservations(
analyser=self,
reservations=self.reservations,
write_state_callback=lambda: None,
)
except Exception:
pass
if not expired:
# 预约回退后直接参与:查找福袋并打开详情页,然后直接参与
try:
self._reservation_back_direct_attend = False # 清除标志
# 设置强制参与标志,让 basic_join_decision 跳过倒计时检查
self._force_attend_after_reservation_back = True
self._log_kv(
"预约",
"[预约] 预约回退后直接参与:查找福袋并打开详情页,设置强制参与标志",
flag_cleared=True,
force_attend=True,
stage=stage,
)
except Exception:
pass
# 回退后等待页面加载和查找福袋都使用 switch_room_wait_after_stage_diag_seconds 参数
try:
wait_seconds = float(
@@ -4183,8 +4267,48 @@ class fudai_analyse:
participants = int(first_reservation.get("participants", 0) or 0)
copies = int(first_reservation.get("copies", 0) or 0)
# 构造倒计时元组
# 检查福袋是否已过期
now_ts = time.time()
poll_before = float(getattr(self, "high_value_fudai_poll_before_seconds", 10.0) or 10.0)
expired_threshold = future_ts + max(0.0, poll_before) # 开奖时间 + 缓冲时间
if future_ts > 0 and now_ts > expired_threshold:
# 福袋已过期,清除标志并退出
try:
from datetime import datetime
future_str = datetime.fromtimestamp(future_ts).strftime("%Y-%m-%d %H:%M:%S") if future_ts > 0 else "无效"
expired_seconds = int(now_ts - expired_threshold)
self._log_kv(
"预约",
"[预约] 预约回退后直接参与:福袋已过期,清除标志并退出",
future_ts=int(future_ts),
future_str=future_str,
expired_threshold=int(expired_threshold),
expired_seconds=expired_seconds,
now_ts=int(now_ts),
)
except Exception:
pass
# 清除相关标志
self._reservation_back_direct_attend = False
self._force_attend_after_reservation_back = False
self.queue_full_waiting_at_earliest = False
# 从预约队列中移除过期预约
try:
import douyin_reservation_logic
douyin_reservation_logic.cleanup_expired_reservations(
analyser=self,
reservations=self.reservations,
write_state_callback=lambda: None, # 暂时不写入,避免重复写入
)
except Exception:
pass
return
# 构造倒计时元组
countdown_start = now_ts
countdown_end = future_ts if future_ts > 0 else (now_ts + 60.0)
+25 -4
View File
@@ -191,9 +191,9 @@ def add_reservation_core_logic(
or room_title_similarity >= 0.6
)
# 开奖时间相近(相差5秒内)
# 开奖时间相近(相差60秒内,放宽容忍度以处理OCR误差和实际时间差)
time_diff = abs(r_ft - ft)
is_similar_time = time_diff <= 5.0
is_similar_time = time_diff <= 60.0
# 奖品价值相同(允许0.01的误差)
prize_diff = abs(r_prize_value - prize_value)
@@ -221,6 +221,22 @@ def add_reservation_core_logic(
elif (room_title_normalized and not r_room_title_normalized) or (not room_title_normalized and r_room_title_normalized):
same_idx = idx
break
# 如果直播间名称相同(规范化后)且价值相同,即使时间差稍大也视为重复
elif is_same_room_title and is_same_prize_value and time_diff <= 300.0:
# 直播间名称相同且价值相同,时间差在5分钟内,视为重复
same_idx = idx
try:
if analyser:
analyser._log_kv(
"预约",
"[预约] 通过直播间名称和价值匹配识别为重复预约",
room_title_normalized=room_title_normalized,
time_diff=round(time_diff, 2),
prize_value_yuan=prize_value,
)
except Exception:
pass
break
elif is_similar_room_title and is_similar_time and is_same_prize_value and is_similar_content:
# 通过相似度匹配判断为同一个预约(处理OCR误差)
same_idx = idx
@@ -657,7 +673,7 @@ def handle_queue_full_wait_at_earliest(
# 1. 回退前已经进行了阶段诊断,处理了弹窗和福袋详情页等异常状态
# 2. 如果已经在直播间,不需要下滑
# 3. 预先下滑会导致 room_pos 减1,影响后续的回退计算,导致少回退一个直播间
# 回退到最早开奖的预约直播间
ok = False
try:
@@ -1031,10 +1047,12 @@ def process_reservation_attend_window(
return True
else:
# 时间窗口未到达,跳过
# 注意:如果已经在目标位置但时间窗口未到,不应该设置 reservation_after_action_pending
# 因为这会导致反复等待,应该清除这个标志,让主循环正常处理
try:
analyser._log_kv(
"预约",
"[预约] 锁定期未结束但是同一个预约,且已在目标位置,但时间窗口未到达,跳过回退",
"[预约] 锁定期未结束但是同一个预约,且已在目标位置,但时间窗口未到达,跳过回退并清除待处理标志",
focus_until=int(focus_until),
target_future_ts=int(ft),
current_room_pos=current_room_pos_check,
@@ -1045,6 +1063,9 @@ def process_reservation_attend_window(
)
except Exception:
pass
# 清除待处理标志,避免反复等待
if reservation_after_action_pending_ref:
reservation_after_action_pending_ref[0] = False
return False
# 如果不在目标位置,继续检查时间窗口
+14 -10
View File
@@ -63,11 +63,11 @@ def swipe_up_switch_live(analyser: Any) -> None:
device_id = getattr(analyser, "device_id", "")
# 基准坐标(1080x2400):从中下部往上滑
# 减少滑动距离:从 1700 到 1000,距离约 700 像素(原来约 1000 像素)
# 恢复原来的滑动距离:从 1700 到 700,距离约 1000 像素
start_x_base = 540
start_y_base = 1700
end_x_base = 540
end_y_base = 1000
end_y_base = 700
start_x = start_x_base * rx // 1080
end_x = end_x_base * rx // 1080
@@ -94,9 +94,11 @@ def swipe_up_switch_live(analyser: Any) -> None:
pass
# 直接使用 ADB 内部滑动命令
# 增加滑动持续时间(从 300ms 增加到 600ms),确保滑动更稳定
# 滑动距离约 1000 像素,600ms 的速度更接近真实用户操作
swipe_duration_ms = 600
# 从配置中读取滑动持续时间(默认600ms),确保滑动更稳定
# 滑动距离约 1000 像素(已恢复),600ms 的速度更接近真实用户操作
swipe_duration_ms = int(
getattr(analyser, "swipe_duration_ms", 600) or 600
)
success = _adb_swipe_direct(device_id, start_x, start_y, end_x, end_y, swipe_duration_ms, analyser.operation)
if not success:
# 如果失败,尝试使用基准坐标(不缩放)
@@ -135,11 +137,11 @@ def swipe_down_back_live(analyser: Any) -> None:
# 基准坐标(1080x2400):从上方往下滑(与上滑切换相反方向)
# 回退操作:从上往下滑动(start_y < end_y)
# 减少滑动距离:从 800 到 1300,距离约 500 像素(原来约 800 像素)
# 恢复原来的滑动距离:从 800 到 1600,距离约 800 像素
start_x_base = 540
start_y_base = 800 # 上方起始位置
end_x_base = 540
end_y_base = 1300 # 下方结束位置
end_y_base = 1600 # 下方结束位置
start_x = start_x_base * rx // 1080
end_x = end_x_base * rx // 1080
@@ -166,9 +168,11 @@ def swipe_down_back_live(analyser: Any) -> None:
pass
# 直接使用 ADB 内部滑动命令
# 增加滑动持续时间(从 300ms 增加到 600ms),确保滑动更稳定
# 滑动距离约 800 像素,600ms 的速度更接近真实用户操作
swipe_duration_ms = 600
# 从配置中读取滑动持续时间(默认600ms),确保滑动更稳定
# 滑动距离约 800 像素(已恢复),600ms 的速度更接近真实用户操作
swipe_duration_ms = int(
getattr(analyser, "swipe_duration_ms", 600) or 600
)
success = _adb_swipe_direct(device_id, start_x, start_y, end_x, end_y, swipe_duration_ms, analyser.operation)
if not success:
# 如果失败,尝试使用基准坐标(不缩放)
+23
View File
@@ -376,6 +376,10 @@ def main():
live_room_match_threshold_var = tk.DoubleVar(
value=float(cfg.get("live_room_match_threshold", 0.8) or 0.8)
)
# 滑动速度(毫秒)
swipe_duration_ms_var = tk.IntVar(
value=int(cfg.get("swipe_duration_ms", 600) or 600)
)
# 推荐页养号:爱心/收藏/评论(基于图标模板匹配 + 坐标点击)
yg_enabled_var = tk.BooleanVar(value=bool(cfg.get("yanghao_enabled", True)))
@@ -994,6 +998,19 @@ def main():
).pack(side=LEFT)
ttk.Label(row4e, text="(阶段检测后等待福袋加载,默认7.0秒)").pack(side=LEFT, padx=(6, 0))
row4f = ttk.Frame(fudai_find_box)
row4f.pack(fill=X, padx=10, pady=(0, 8))
ttk.Label(row4f, text="滑动速度(毫秒):").pack(side=LEFT)
ttk.Spinbox(
row4f,
from_=100,
to=2000,
increment=50,
textvariable=swipe_duration_ms_var,
width=6,
).pack(side=LEFT)
ttk.Label(row4f, text="(滑动持续时间,默认600ms,值越大滑动越慢)").pack(side=LEFT, padx=(6, 0))
row4c = ttk.Frame(fudai_find_box)
row4c.pack(fill=X, padx=10, pady=(0, 10))
ttk.Label(row4c, text="直播间检测阈值:").pack(side=LEFT)
@@ -1234,6 +1251,9 @@ def main():
live_room_match_threshold_var.set(
float(cfg.get("live_room_match_threshold", 0.8) or 0.8)
)
swipe_duration_ms_var.set(
int(cfg.get("swipe_duration_ms", 600) or 600)
)
fudai_quiet_hours_enabled_var.set(
bool(cfg.get("fudai_quiet_hours_enabled", True))
)
@@ -1430,6 +1450,9 @@ def main():
cfg2["live_room_match_threshold"] = float(
live_room_match_threshold_var.get() or 0.8
)
cfg2["swipe_duration_ms"] = int(
swipe_duration_ms_var.get() or 600
)
cfg2["fudai_quiet_hours_enabled"] = bool(fudai_quiet_hours_enabled_var.get())
cfg2["fudai_quiet_start_hour"] = int(fudai_quiet_start_hour_var.get() or 0)
cfg2["fudai_quiet_end_hour"] = int(fudai_quiet_end_hour_var.get() or 0)
+2
View File
@@ -124,6 +124,8 @@ paddlepaddle>=2.5.0,<3.0.0
+2
View File
@@ -101,6 +101,8 @@ types-requests>=2.31.0
+2
View File
@@ -140,6 +140,8 @@ ttkbootstrap>=1.10.0
+2
View File
@@ -177,6 +177,8 @@ if __name__ == "__main__":
+40 -18
View File
@@ -1,29 +1,51 @@
{
"updated_ts": 1766819941.2713513,
"reason": "process_reservation",
"room_pos": 3,
"current_room_title": "希娜周",
"current_room_title_raw": "希娜周",
"updated_ts": 1766826599.1160014,
"reason": "record_reservation",
"room_pos": 19,
"current_room_title": "小北珠宝",
"current_room_title_raw": "小北珠宝",
"reservations": [
{
"prize_value_yuan": 899.0,
"content": "04后开奖04Syna定制大哥水桶包595人巳参与",
"future_ts": 1766820020.879266,
"future_str": "2025-12-27 15:20:20",
"pos_seen": 3,
"room_title": "希娜周",
"room_title_raw": "希娜周",
"created_ts": 1766819777.8944454
"prize_value_yuan": 1888.0,
"content": "44后开奖10(小北珠宝』和田玉碧玉手(圈口随机)(假一赔。镯",
"future_ts": 1766826687.020912,
"future_str": "2025-12-27 17:11:27",
"pos_seen": 7,
"room_title": "小北珠宝卜",
"room_title_raw": "小北珠宝卜",
"created_ts": 1766826082.0641146,
"task_count": 2,
"time_text": "10:14",
"participants": 2053,
"copies": 1
},
{
"prize_value_yuan": 1888.0,
"content": "46后开奖11(小北珠宝』和田玉碧玉手(圈口随机)(假一赔。镯",
"future_ts": 1766820342.793937,
"future_str": "2025-12-27 15:25:42",
"pos_seen": 0,
"content": "36|后开奖14(小北珠宝』和田玉碧玉手(圈口随机)(假一赔。镯737人巳参与",
"future_ts": 1766826694.307182,
"future_str": "2025-12-27 17:11:34",
"pos_seen": 1,
"room_title": "小北珠宝",
"room_title_raw": "小北珠宝",
"created_ts": 1766819678.3075242
"created_ts": 1766825850.1467466,
"task_count": 2,
"time_text": "14:13",
"participants": 0,
"copies": 1
},
{
"prize_value_yuan": 1888.0,
"content": "56后开奖13(小北珠宝』和田玉碧玉手(圈口随机)(假一赔。镯",
"future_ts": 1766826716.852443,
"future_str": "2025-12-27 17:11:56",
"pos_seen": 2,
"room_title": "小北珠宝",
"room_title_raw": "小北珠宝",
"created_ts": 1766825889.268038,
"task_count": 2,
"time_text": "13:56",
"participants": 1056,
"copies": 1
}
]
}
+2
View File
@@ -100,6 +100,8 @@ if os.path.exists(log_file):
+2
View File
@@ -113,6 +113,8 @@ if os.path.exists(log_file):
+2
View File
@@ -246,6 +246,8 @@ pytest --pdb --pdbcls=IPython.terminal.debugger:Pdb
+2
View File
@@ -83,6 +83,8 @@ __version__ = "1.0.0"
+2
View File
@@ -72,6 +72,8 @@
+2
View File
@@ -72,6 +72,8 @@
+2
View File
@@ -162,6 +162,8 @@ python check_gpu_available.py
+2
View File
@@ -168,6 +168,8 @@
+2
View File
@@ -240,6 +240,8 @@ if __name__ == "__main__":
+2
View File
@@ -168,6 +168,8 @@
+2
View File
@@ -372,3 +372,5 @@