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, enhancing overall project clarity.
- Updated logging mechanisms for better consistency and debugging support.
This commit is contained in:
Your Name committed 2025-12-26 14:54:26 +08:00
1 parent f36f1a9593
commit 5d22250b05
35 files changed
+15431 -3674

No files matched your search

File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+2
View File
@@ -170,6 +170,8 @@ python cleanup_unused_files.py
+2
View File
@@ -181,6 +181,8 @@ except Exception as e:
+2
View File
@@ -384,6 +384,8 @@ self.last_fudai_x: int = 0 # 上次检测到的福袋图标X坐标
+2
View File
@@ -268,6 +268,8 @@ YYYYMMDD_HHMMSS_操作类型_图片名_步骤_坐标_额外信息.png
+2
View File
@@ -239,6 +239,8 @@ python check_dependencies.py
+2
View File
@@ -218,6 +218,8 @@ douyin_guaji
+2
View File
@@ -159,6 +159,8 @@
+2
View File
@@ -371,6 +371,8 @@ douyin_fudai_finder.py
+2
View File
@@ -170,6 +170,8 @@ self.ocr = easyocr.Reader(
+50 -38
View File
@@ -1109,43 +1109,45 @@ class underlying_operations:
img1 = img # img1 is used later, initialize from img
img2 = None
text2 = None
if (not text) and max(w, h) <= 1200:
try:
img2 = img.resize((w * 2, h * 2), _RESAMPLE.LANCZOS)
try:
from PIL import ImageEnhance
img2_sharpened = img2.filter(
ImageFilter.UnsharpMask(radius=1.5, percent=180, threshold=3)
)
enhancer = ImageEnhance.Contrast(img2_sharpened)
img2 = enhancer.enhance(1.2)
except Exception:
img2 = img2.filter(ImageFilter.SHARPEN)
if getattr(self, "ocr_type", None) == "easyocr":
result2 = self.ocr.readtext(np.array(img2))
extract_result2 = self.extract_ocr_content(result2, return_confidence=True)
if isinstance(extract_result2, tuple):
text2, ocr_confidence_info = extract_result2
else:
text2 = extract_result2
if text2:
text = text2
result = result2
else:
result2 = self.ocr.ocr(np.array(img2))
if result2 != [None]:
extract_result2 = self.extract_ocr_content(result2, return_confidence=True)
if isinstance(extract_result2, tuple):
text2, ocr_confidence_info = extract_result2
else:
text2 = extract_result2
if text2:
text = text2
result = result2
except Exception:
pass
# 禁用二次OCR识别(用户要求:没有GPU,不需要二次OCR)
# 如果第一次识别失败,直接返回空结果,避免耗时3-4秒的二次识别
# if (not text) and max(w, h) <= 1200:
# try:
# img2 = img.resize((w * 2, h * 2), _RESAMPLE.LANCZOS)
# try:
# from PIL import ImageEnhance
#
# img2_sharpened = img2.filter(
# ImageFilter.UnsharpMask(radius=1.5, percent=180, threshold=3)
# )
# enhancer = ImageEnhance.Contrast(img2_sharpened)
# img2 = enhancer.enhance(1.2)
# except Exception:
# img2 = img2.filter(ImageFilter.SHARPEN)
#
# if getattr(self, "ocr_type", None) == "easyocr":
# result2 = self.ocr.readtext(np.array(img2))
# extract_result2 = self.extract_ocr_content(result2, return_confidence=True)
# if isinstance(extract_result2, tuple):
# text2, ocr_confidence_info = extract_result2
# else:
# text2 = extract_result2
# if text2:
# text = text2
# result = result2
# else:
# result2 = self.ocr.ocr(np.array(img2))
# if result2 != [None]:
# extract_result2 = self.extract_ocr_content(result2, return_confidence=True)
# if isinstance(extract_result2, tuple):
# text2, ocr_confidence_info = extract_result2
# else:
# text2 = extract_result2
# if text2:
# text = text2
# result = result2
# except Exception:
# pass
if picname in ("福袋内容", "福袋倒计时") and not text:
try:
@@ -1650,9 +1652,19 @@ class underlying_operations:
right_down_y=1500,
steps=200,
):
"""划动屏幕"""
"""划动屏幕
参数说明:
- left_up_x, left_up_y: 滑动起始位置(手指按下位置)
- right_down_x, right_down_y: 滑动结束位置(手指抬起位置)
- steps: 滑动步数(影响滑动速度,数值越大滑动越慢)
执行命令:adb shell input swipe <start_x> <start_y> <end_x> <end_y> <duration_ms>
"""
import subprocess
adb_cmd = self._adb()
# 注意:adb input swipe 的参数顺序是:start_x start_y end_x end_y duration_ms
# 这里 left_up_x/y 是起始位置,right_down_x/y 是结束位置
cmd = f"{adb_cmd} -s {device_id} shell input swipe {left_up_x} {left_up_y} {right_down_x} {right_down_y} {steps}"
try:
+2
View File
@@ -129,6 +129,8 @@ python 生成WPS流程图.py
+2
View File
@@ -143,6 +143,8 @@ else:
+7 -7
View File
@@ -2,7 +2,7 @@
"needswitch": true,
"infinite_loop_enabled": true,
"wait_minutes": 5,
"min_prize_value_yuan": 100.0,
"min_prize_value_yuan": 200.0,
"min_participants": 0,
"max_participants": 0,
"skip_if_countdown_gt_seconds": 120,
@@ -11,10 +11,10 @@
"auto_join_fansclub": true,
"fansclub_fail_action": "switch",
"high_value_fudai_enabled": true,
"high_value_fudai_threshold_yuan": 100.0,
"high_value_fudai_join_ahead_seconds": 90,
"high_value_fudai_threshold_yuan": 500.0,
"high_value_fudai_join_ahead_seconds": 120,
"high_value_fudai_max_swipe_back": 50,
"high_value_fudai_max_reservations": 3,
"high_value_fudai_max_reservations": 9999,
"high_value_fudai_after_action": "continue",
"high_value_room_revisit_enabled": true,
"high_value_room_revisit_only_current_run": true,
@@ -28,8 +28,8 @@
"yanghao_fallback_enter_live_x": 540,
"yanghao_fallback_enter_live_y": 1200,
"fudai_find_max_attempts": 99999,
"fudai_icon_retry_delay_seconds": 0.4,
"fudai_icon_max_wait_seconds": 5.0,
"fudai_icon_retry_delay_seconds": 0.1,
"fudai_icon_max_wait_seconds": 8.0,
"fudai_click_wait_seconds": 1.7,
"yanghao_recommend_duration_seconds": 206,
"yanghao_recommend_interval_seconds": 570,
@@ -100,7 +100,7 @@
"auto_cleanup": true
},
"fudai_detail_template_threshold": 0.54,
"switch_room_wait_after_stage_diag_seconds": 8.0,
"switch_room_wait_after_stage_diag_seconds": 4.0,
"coupon_template_match_threshold": 0.4,
"attend_button_red_ratio_threshold": 0.25,
"fansclub_join_red_ratio_threshold": 0.25,
+44 -16
View File
@@ -2453,13 +2453,28 @@ class fudai_analyse:
top_pkg = ""
try:
top_pkg = self.operation.get_top_package(self.device_id) or ""
except Exception:
self._log_kv("自救", "桌面检测:获取前台包名", top_pkg=top_pkg)
except Exception as e:
top_pkg = ""
if top_pkg and (
"aweme" not in top_pkg
and "douyin" not in top_pkg
and "com.ss.android.ugc" not in top_pkg
):
self._log_kv("自救", "桌面检测:获取前台包名失败", error=str(e))
# 如果获取到包名且不是抖音相关包,说明可能在桌面或其他应用
is_douyin_pkg = (
top_pkg
and (
"aweme" in top_pkg
or "douyin" in top_pkg
or "com.ss.android.ugc" in top_pkg
)
)
if top_pkg and not is_douyin_pkg:
self._log_kv(
"自救",
"桌面检测:检测到不在抖音前台",
top_pkg=top_pkg,
is_douyin=False,
)
try:
self._log_kv(
"自救",
@@ -2493,21 +2508,34 @@ class fudai_analyse:
self.operation.delay(2.0)
except Exception:
pass
# 重新开始下一轮判断
elapsed = time.time() - start_time
self._log_kv(
"流程",
"run_once_basic完成(恢复进入直播间)",
elapsed_seconds=round(elapsed, 2),
)
# 自救完成后,不在这里结束本轮流程,而是立即重新执行一次主流程:
# 重新截图 + 阶段诊断 + 查找福袋,使流程与正常进入直播间路径保持一致
try:
self._log_kv(
"流程",
"run_once_basic:自救完成,立即重新执行一次主流程",
)
except Exception:
pass
# 为避免递归过深,仅在当前检测到不在抖音前台的场景下递归一次;
# 自救完成后前台包名应为抖音,下一次 run_once_basic 将不会再次进入自救分支。
try:
self.operation.delay(0.5)
except Exception:
time.sleep(0.5)
self.run_once_basic()
return
except Exception as e:
try:
self._log_kv("自救", "恢复失败", error=str(e))
self._log_kv("自救", "恢复失败", error=str(e), error_type=type(e).__name__)
except Exception:
pass
except Exception:
pass
except Exception as e:
# 桌面检测本身出错,记录日志
try:
self._log_kv("自救", "桌面检测异常", error=str(e), error_type=type(e).__name__)
except Exception:
pass
# 2. 诊断后分支(弹窗检测已合并到阶段诊断中)
# 处理弹窗阶段
+1024 -490
View File
File diff suppressed because it is too large. Load diff
+49 -12
View File
@@ -278,8 +278,20 @@ def get_debug_captures_dir() -> str:
def ensure_debug_captures_dir() -> None:
"""确保调试图像存档目录存在"""
debug_dir = get_debug_captures_dir()
os.makedirs(debug_dir, exist_ok=True)
try:
debug_dir = get_debug_captures_dir()
# 确保父目录也存在
parent_dir = os.path.dirname(debug_dir)
if parent_dir and not os.path.exists(parent_dir):
os.makedirs(parent_dir, exist_ok=True)
os.makedirs(debug_dir, exist_ok=True)
except Exception as e:
# 如果目录创建失败,记录错误但不抛出异常(让调用方处理)
try:
print(f"[截图管理] 创建调试图像目录失败: {e}")
except Exception:
pass
raise
def get_debug_captures_base_dir() -> str:
@@ -658,24 +670,49 @@ def save_debug_image(
clean_key = _sanitize_filename_part(str(key))
clean_value = _sanitize_filename_part(str(value))
# 限制值的长度,避免文件名过长
if len(clean_value) > 50:
clean_value = clean_value[:50]
# 对于 text_preview 等长文本,限制更短(20字符)
if key == "text_preview" or key == "content":
if len(clean_value) > 20:
clean_value = clean_value[:20]
else:
if len(clean_value) > 30:
clean_value = clean_value[:30]
parts.append(f"{clean_key}_{clean_value}")
filename_parts = [timestamp] + parts
filename = "_".join(str(p) for p in filename_parts if p) + ".png"
# Windows文件名长度限制(260字符),自动截断
max_len = 200 # 留一些余量
# 考虑完整路径长度,文件名部分限制更严格
max_len = 180 # 留更多余量,考虑目录路径长度
if len(filename) > max_len:
# 保留时间戳和关键信息,截断其他部分
base = f"{timestamp}_{operation_type}_{picname}_{step}"
if len(base) < max_len - 20:
remaining = max_len - len(base) - 20
if coords:
coord_str = f"({coords[0]},{coords[1]})-({coords[2]},{coords[3]})"
if len(coord_str) <= remaining:
base += f"_{coord_str}"
# 优先保留:时间戳、操作类型、图片名、步骤
base_parts = [timestamp]
if operation_type:
base_parts.append(_sanitize_filename_part(operation_type))
if picname:
base_parts.append(_sanitize_filename_part(picname))
if step:
base_parts.append(_sanitize_filename_part(step))
base = "_".join(base_parts)
# 如果还有空间,添加最重要的额外信息(排除长文本)
remaining = max_len - len(base) - 10 # 留10字符余量
if remaining > 20 and extra_info:
important_keys = ["mode", "size", "used_img2", "avg_confidence"]
for key in important_keys:
if key in extra_info and remaining > 0:
clean_key = _sanitize_filename_part(str(key))
clean_value = _sanitize_filename_part(str(extra_info[key]))
if len(clean_value) > 15:
clean_value = clean_value[:15]
part = f"{clean_key}_{clean_value}"
if len(part) <= remaining:
base += f"_{part}"
remaining -= len(part) + 1
filename = base[:max_len] + ".png"
file_path = os.path.join(debug_dir, filename)
+16
View File
@@ -38,12 +38,20 @@ def swipe_up_switch_live(analyser: Any) -> None:
start_y=start_y_base,
end_x=end_x_base,
end_y=end_y_base,
start_x_scaled=start_x,
start_y_scaled=start_y,
end_x_scaled=end_x,
end_y_scaled=end_y,
resolution=f"{rx}x{ry}",
swipe_from=f"({start_x}, {start_y})",
swipe_to=f"({end_x}, {end_y})",
)
except Exception:
pass
# 优先调用底层 swipe,失败则静默忽略(不影响主流程)
try:
# 执行滑动操作:从 (start_x, start_y) 滑到 (end_x, end_y)
analyser.operation.swipe(device_id, start_x, start_y, end_x, end_y, 300)
except Exception:
try:
@@ -91,12 +99,20 @@ def swipe_down_back_live(analyser: Any) -> None:
start_y=start_y_base,
end_x=end_x_base,
end_y=end_y_base,
start_x_scaled=start_x,
start_y_scaled=start_y,
end_x_scaled=end_x,
end_y_scaled=end_y,
resolution=f"{rx}x{ry}",
swipe_from=f"({start_x}, {start_y})",
swipe_to=f"({end_x}, {end_y})",
)
except Exception:
pass
# 优先调用底层 swipe,失败则静默忽略(不影响主流程)
try:
# 执行滑动操作:从 (start_x, start_y) 滑到 (end_x, end_y)
analyser.operation.swipe(device_id, start_x, start_y, end_x, end_y, 300)
except Exception:
try:
+2
View File
@@ -143,6 +143,8 @@ def extract_participants_count(text: Optional[str]) -> int:
+2
View File
@@ -100,6 +100,8 @@ paddlepaddle>=2.5.0,<3.0.0
+2
View File
@@ -77,6 +77,8 @@ types-requests>=2.31.0
+2
View File
@@ -116,6 +116,8 @@ ttkbootstrap>=1.10.0
+2
View File
@@ -153,6 +153,8 @@ if __name__ == "__main__":
+21 -11
View File
@@ -1,19 +1,29 @@
{
"updated_ts": 1766724849.1728284,
"reason": "record_reservation",
"updated_ts": 1766731949.3357337,
"reason": "process_reservation",
"room_pos": 0,
"current_room_title": "小宝珠宝2",
"current_room_title_raw": "小宝珠宝2..",
"current_room_title": "颜妍记",
"current_room_title_raw": "颜妍记.",
"reservations": [
{
"prize_value_yuan": 9999.0,
"content": "03后开奖05首饰盒1箱(小宝珠宝1木质首饰盒/箱首饰盒-发1个",
"future_ts": 1766725149.202263,
"future_str": "2025-12-26 12:59:09",
"prize_value_yuan": 1199.0,
"content": "58后开奖04(叨叨专属』创维智能影音娱乐平板",
"future_ts": 1766732049.327057,
"future_str": "2025-12-26 14:54:09",
"pos_seen": 0,
"room_title": "小宝珠宝2",
"room_title_raw": "小宝珠宝2..",
"created_ts": 1766724849.1696897
"room_title": "米叨叨",
"room_title_raw": "米叨叨",
"created_ts": 1766731753.97193
},
{
"prize_value_yuan": 1699.0,
"content": "36后开奖11(颜研专属1全新智能大屏追剧安卓国产颜色随机",
"future_ts": 1766732498.232999,
"future_str": "2025-12-26 15:01:38",
"pos_seen": 2,
"room_title": "颜妍记",
"room_title_raw": "颜妍记.",
"created_ts": 1766731804.78279
}
]
}
+2
View File
@@ -76,6 +76,8 @@ if os.path.exists(log_file):
+2
View File
@@ -89,6 +89,8 @@ if os.path.exists(log_file):
+2
View File
@@ -222,6 +222,8 @@ pytest --pdb --pdbcls=IPython.terminal.debugger:Pdb
+2
View File
@@ -59,6 +59,8 @@ __version__ = "1.0.0"
+2
View File
@@ -48,6 +48,8 @@
+2
View File
@@ -48,6 +48,8 @@
+2
View File
@@ -138,6 +138,8 @@ python check_gpu_available.py
+2
View File
@@ -144,6 +144,8 @@
+2
View File
@@ -216,6 +216,8 @@ if __name__ == "__main__":
+2
View File
@@ -147,3 +147,5 @@