Files
douyin_guaji-main/path_demo.py
T
Your Name 26df350755 feat: Implement 30-minute timeout protection and unify path configurations
- Introduced a 30-minute timeout mechanism to prevent the script from getting stuck in invalid states, with configurable timeout settings.
- Unified path configurations across the project to enhance maintainability and avoid hardcoded paths.
- Updated documentation and flowcharts to reflect the new timeout feature and improved path management.
- Fixed issues with template and screenshot path configurations to ensure consistency across the project.
2025-12-28 14:47:31 +08:00

79 lines
2.7 KiB
Python

import os
import sys
sys.path.append('.')
# 演示统一的路径配置 vs 旧的路径配置的区别
print("=== 路径配置对比演示 ===\n")
# 项目根目录
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
print(f"项目根目录: {PROJECT_ROOT}\n")
# ===== 统一路径配置 =====
print("=== 统一路径配置 (path_config.py) ===")
try:
import path_config
unified_screenshot = path_config.get_screenshot_path()
unified_assets = path_config.get_assets_dir()
unified_pic = path_config.get_pic_dir()
print(f" 截图路径: {unified_screenshot}")
print(f" assets路径: {unified_assets}")
print(f" pic路径: {unified_pic}")
print(" OK 始终指向项目根目录下的正确目录")
except Exception as e:
print(f" FAIL 导入失败: {e}")
print("\n" + "="*50 + "\n")
# ===== 旧的路径配置 =====
print("=== 旧的路径配置 (硬编码相对路径) ===")
# 模拟不同文件中的旧路径配置
files_and_old_paths = [
("douyin/stage/douyin_stage_handler.py", "douyin/stage"),
("douyin/utils/douyin_helpers.py", "douyin/utils"),
("douyin/other/douyin_popups.py", "douyin/other"),
("fudai_detail_modules/fudai_detail_coupon_detection.py", "fudai_detail_modules"),
]
for file_path, module_dir in files_and_old_paths:
print(f"\nFile: {file_path}")
print(f" 模块目录: {module_dir}")
# 旧的硬编码路径
old_base_dir = os.path.join(PROJECT_ROOT, module_dir)
old_screenshot = os.path.join(old_base_dir, "pic", "screenshot.png")
old_assets = os.path.join(old_base_dir, "assets")
print(f" OLD 旧截图路径: {old_screenshot}")
print(f" OLD 旧assets路径: {old_assets}")
# 检查这些路径是否存在
screenshot_exists = os.path.exists(old_screenshot)
assets_exists = os.path.exists(old_assets)
print(f" 截图文件存在: {'OK' if screenshot_exists else 'MISSING'}")
print(f" assets目录存在: {'OK' if assets_exists else 'MISSING'}")
print("\n" + "="*50 + "\n")
# ===== 实际对比 =====
print("=== 实际对比 ===")
print("OK 统一路径: 总是指向项目根目录的正确位置")
print("FAIL 旧路径: 根据文件位置动态变化,可能指向错误目录")
print("\n=== 影响 ===")
print("• 模板匹配失败 → 直播间检测错误")
print("• 截图读取失败 → 像素检测异常")
print("• 文件找不到 → 功能无法正常工作")
print("\n=== 修复方法 ===")
print("• 使用 path_config.py 中的统一路径函数")
print("• 确保所有文件都使用相同的基准目录(项目根目录)")
print("\n=== 修复结果 ===")
print("• 模板匹配正常工作 (分数0.957)")
print("• 像素检测返回完整信息")
print("• 警告信息消失")