refactor: 根目录核心模块迁移到 douyin/core/ 和 douyin/logging/
将 4 个根目录核心模块迁移到合理位置: - path_config.py -> douyin/core/path_config.py - version.py -> douyin/core/version.py - Underlying_Operations.py -> douyin/core/underlying_operations.py - unified_logger.py -> douyin/logging/unified_logger.py 配套更新所有 import: - path_config: 41 处 import 改为 douyin.core.path_config - version: 4 处改为 douyin.core.version - unified_logger: 5 处改为 douyin.logging.unified_logger - Underlying_Operations: 14 处改为 douyin.core.underlying_operations 修复 path_config.PROJECT_ROOT 计算(向上 2 级而非当前目录)。 验证:python -m compileall 全项目通过。 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e3e399da70
commit
8fe7ff0585
51 files changed
+136
-132
No files matched your search
+1
-1
@@ -631,7 +631,7 @@ def main(argv: list[str]) -> int:
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
from version import print_version_banner
|
||||
from douyin.core.version import print_version_banner
|
||||
|
||||
print_version_banner("run_cli")
|
||||
except Exception:
|
||||
|
||||
@@ -18,7 +18,7 @@ import os
|
||||
|
||||
from douyin.detection.douyin_detection import check_have_fudai_with_ready_screenshot
|
||||
from douyin.fudai.douyin_fudai_core import should_skip_fudai_by_config
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
|
||||
def handle_stage_after_diagnosis(
|
||||
|
||||
@@ -20,7 +20,7 @@ import logging
|
||||
from PIL import Image # type: ignore[import]
|
||||
import numpy as np # type: ignore[import]
|
||||
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
|
||||
from douyin.stage import douyin_stage
|
||||
from douyin.detection import douyin_detection
|
||||
@@ -99,7 +99,7 @@ class fudai_analyse:
|
||||
logging.warning("日志系统初始化失败: %s", e)
|
||||
|
||||
try:
|
||||
from unified_logger import MDC, get_unified_logger
|
||||
from douyin.logging.unified_logger import MDC, get_unified_logger
|
||||
|
||||
# 为当前实例设置traceId
|
||||
MDC.set_trace_id(f"run_{self._run_id}")
|
||||
@@ -563,7 +563,7 @@ class fudai_analyse:
|
||||
"""兼容原 fudai1.fudai_choujiang 的主入口(当前实现为精简版:仅基础抢福袋)。"""
|
||||
# 程序启动时清理旧截图文件,避免复用过期的截图
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
import os
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
@@ -855,7 +855,7 @@ class fudai_analyse:
|
||||
返回 ROI 图片路径(绝对路径),失败返回空字符串。
|
||||
"""
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
# use module-level `Image`
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class MainLogicMixin(BaseFudaiMixin):
|
||||
# #region agent log
|
||||
import json
|
||||
import time as time_module
|
||||
from path_config import get_debug_log_path
|
||||
from douyin.core.path_config import get_debug_log_path
|
||||
|
||||
current_ts = int(time_module.time() * 1000)
|
||||
with open(get_debug_log_path(), "a", encoding="utf-8") as f:
|
||||
@@ -143,7 +143,7 @@ class MainLogicMixin(BaseFudaiMixin):
|
||||
|
||||
# #region agent log
|
||||
import json
|
||||
from path_config import get_debug_log_path
|
||||
from douyin.core.path_config import get_debug_log_path
|
||||
|
||||
with open(get_debug_log_path(), "a", encoding="utf-8") as f:
|
||||
f.write(
|
||||
|
||||
@@ -5,7 +5,11 @@ import os
|
||||
from typing import Optional
|
||||
|
||||
# 项目根目录(所有路径的基准)
|
||||
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
|
||||
# __file__ 位于 <project_root>/douyin/core/path_config.py,
|
||||
# 所以项目根是当前文件向上两级目录。
|
||||
PROJECT_ROOT = os.path.dirname(
|
||||
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
)
|
||||
|
||||
|
||||
def get_project_root() -> str:
|
||||
@@ -495,11 +495,11 @@ class underlying_operations:
|
||||
图片的完整路径,如果找不到且for_reading=True则返回None
|
||||
"""
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_base = path_config.get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_base = path_config.get_pic_dir()
|
||||
|
||||
@@ -747,11 +747,11 @@ class underlying_operations:
|
||||
|
||||
if path == "pic":
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
out_dir = path_config.get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
out_dir = path_config.get_pic_dir()
|
||||
else:
|
||||
@@ -1281,11 +1281,11 @@ class underlying_operations:
|
||||
|
||||
def save_reward_pic(self, device_id):
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
out_dir = path_config.get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
out_dir = path_config.get_pic_dir()
|
||||
if not os.path.exists(out_dir):
|
||||
@@ -1678,7 +1678,7 @@ class underlying_operations:
|
||||
|
||||
if save_debug:
|
||||
from douyin.handlers import douyin_screenshot_manager
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
# 尝试获取OCR区域坐标
|
||||
ocr_coords = None
|
||||
@@ -1874,7 +1874,7 @@ class underlying_operations:
|
||||
# 加载完整截图
|
||||
full_screenshot = None
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
screenshot_path = path_config.get_screenshot_path()
|
||||
if os.path.exists(screenshot_path):
|
||||
@@ -2050,7 +2050,7 @@ class underlying_operations:
|
||||
# 保存预处理后的调试图像(OCR前)- 使用完整截图
|
||||
try:
|
||||
from douyin.handlers import douyin_screenshot_manager
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
# 尝试获取OCR区域坐标
|
||||
ocr_coords = None
|
||||
@@ -2119,7 +2119,7 @@ class underlying_operations:
|
||||
# 保存OCR结果后的调试图像(带OCR文本结果和置信度)- 使用完整截图
|
||||
try:
|
||||
from douyin.handlers import douyin_screenshot_manager
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
# 尝试获取OCR区域坐标
|
||||
ocr_coords = None
|
||||
@@ -3375,11 +3375,11 @@ class underlying_operations:
|
||||
return False
|
||||
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
local_path = path_config.get_window_dump_path()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
local_path = path_config.get_window_dump_path()
|
||||
start = time_module.time()
|
||||
@@ -3428,11 +3428,11 @@ class underlying_operations:
|
||||
如果没有文字,就在顶部区域按“最像关闭”的位置进行启发式选择。
|
||||
"""
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
local_path = path_config.get_window_dump_path()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
local_path = path_config.get_window_dump_path()
|
||||
start = time_module.time()
|
||||
File renamed without changes.
@@ -39,12 +39,12 @@ def check_detail_height(analyser: Any) -> int:
|
||||
"""
|
||||
# 使用统一的截图路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic1_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic1_path = path_config.get_screenshot_path()
|
||||
|
||||
@@ -310,12 +310,12 @@ def check_have_fudai_with_ready_screenshot(
|
||||
func_start = time.time()
|
||||
# 使用统一的截图路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic1_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic1_path = path_config.get_screenshot_path()
|
||||
attempt_count = 0 # 仅用于日志记录,不影响循环控制
|
||||
@@ -847,7 +847,7 @@ def check_have_fudai_with_ready_screenshot(
|
||||
|
||||
# 获取模板路径
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
template_path = path_config.get_assets_dir() + "/fudai.png"
|
||||
except Exception:
|
||||
@@ -1243,7 +1243,7 @@ def check_have_fudai_with_ready_screenshot(
|
||||
|
||||
# 获取模板路径
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
template_path = path_config.get_assets_dir() + "/fudai.png"
|
||||
except Exception:
|
||||
@@ -1729,7 +1729,7 @@ def check_in_fudai_detail(analyser: Any) -> bool:
|
||||
# 使用模板匹配检测,与 detect_fudai_detail_page 保持一致
|
||||
try:
|
||||
from douyin.detection import douyin_pixel
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
# 获取截图
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
|
||||
@@ -99,7 +99,7 @@ def detect_coupon_popup_background(
|
||||
|
||||
# 使用统一的模板路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
template_path = path_config.get_assets_dir() + "/coupon.png"
|
||||
except Exception:
|
||||
|
||||
@@ -9,7 +9,7 @@ import os
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
|
||||
def attend_choujiang(analyser) -> bool:
|
||||
@@ -432,7 +432,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
# 设置等待开奖标志,避免参与后立即切换直播间
|
||||
# #region agent log - set countdown
|
||||
import json
|
||||
from path_config import get_debug_log_path
|
||||
from douyin.core.path_config import get_debug_log_path
|
||||
|
||||
current_ts_debug = int(time.time() * 1000)
|
||||
with open(get_debug_log_path(), "a", encoding="utf-8") as f:
|
||||
|
||||
@@ -11,7 +11,7 @@ import traceback
|
||||
from typing import Any, Tuple, Optional, Dict
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
|
||||
def log_debug_error(
|
||||
|
||||
@@ -11,7 +11,7 @@ import os
|
||||
from typing import Tuple, Any
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
from douyin.fudai.core.fudai_debug_utils import _save_full_screenshot_with_ocr_region
|
||||
from douyin.fudai.core.fudai_filter import is_watch_task_fudai
|
||||
from douyin.utils.douyin_utils import extract_prize_value_yuan
|
||||
|
||||
@@ -11,7 +11,7 @@ import numpy as np # type: ignore[import]
|
||||
|
||||
from douyin.utils.douyin_utils import extract_prize_value_yuan
|
||||
from douyin.reservation import douyin_reservation_logic
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
# 从新模块导入调试工具函数
|
||||
from douyin.fudai.core.fudai_debug_utils import (
|
||||
|
||||
@@ -18,7 +18,7 @@ import os
|
||||
import time
|
||||
from typing import Any, Optional, Tuple, Dict
|
||||
from PIL import Image
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
# OCR 预处理接口(直接导入)
|
||||
from douyin.utils.ocr_preprocess import preprocess_for_ocr # type: ignore
|
||||
|
||||
@@ -14,7 +14,7 @@ import os
|
||||
import shutil
|
||||
from typing import Optional, Tuple
|
||||
from PIL import Image
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
import threading
|
||||
from queue import Queue, Empty
|
||||
from typing import Any
|
||||
|
||||
@@ -19,7 +19,7 @@ import os
|
||||
import sys
|
||||
import json
|
||||
from typing import Optional, Dict, Any
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
|
||||
# 日志配置默认值
|
||||
|
||||
@@ -30,7 +30,7 @@ import threading
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional, Callable, Any, Dict
|
||||
from functools import wraps
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
|
||||
# 全局日志配置
|
||||
@@ -860,7 +860,7 @@ def configure_logging(
|
||||
file_handler.setLevel(numeric_level)
|
||||
# 使用自定义Formatter以支持traceId
|
||||
try:
|
||||
from unified_logger import UnifiedFormatter
|
||||
from douyin.logging.unified_logger import UnifiedFormatter
|
||||
|
||||
file_formatter = UnifiedFormatter(
|
||||
detailed_format, datefmt="%Y-%m-%d %H:%M:%S"
|
||||
|
||||
@@ -396,7 +396,7 @@ class LoggingWrapper:
|
||||
# 获取日志格式模式配置(simple 或 detailed)
|
||||
log_format_mode = "simple" # 默认简洁模式
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
import json
|
||||
|
||||
config_path = path_config.get_config_path()
|
||||
@@ -511,7 +511,7 @@ class LoggingWrapper:
|
||||
|
||||
# 写入 actions.log 文件
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
actions_log_path = path_config.get_actions_log_path()
|
||||
log_dir = path_config.get_logs_dir()
|
||||
@@ -949,7 +949,7 @@ class LoggingWrapper:
|
||||
|
||||
# 写入 actions.log 文件
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
actions_log_path = path_config.get_actions_log_path()
|
||||
log_dir = path_config.get_logs_dir()
|
||||
@@ -1012,7 +1012,7 @@ class LoggingWrapper:
|
||||
|
||||
if not hasattr(analyser, "_std_logger") or analyser._std_logger is None:
|
||||
try:
|
||||
from unified_logger import get_unified_logger
|
||||
from douyin.logging.unified_logger import get_unified_logger
|
||||
|
||||
analyser._std_logger = get_unified_logger("douyin.fudai")
|
||||
except ImportError:
|
||||
@@ -1030,7 +1030,7 @@ class LoggingWrapper:
|
||||
std_msg_parts.append(f"[调用:{caller_info}]")
|
||||
if msg:
|
||||
try:
|
||||
from unified_logger import SensitiveDataMasker
|
||||
from douyin.logging.unified_logger import SensitiveDataMasker
|
||||
|
||||
masked_msg = SensitiveDataMasker.mask_all(str(msg))
|
||||
std_msg_parts.append(masked_msg)
|
||||
@@ -1039,7 +1039,7 @@ class LoggingWrapper:
|
||||
|
||||
masked_fields: Dict[str, Any] = {}
|
||||
try:
|
||||
from unified_logger import SensitiveDataMasker
|
||||
from douyin.logging.unified_logger import SensitiveDataMasker
|
||||
|
||||
masked_fields = SensitiveDataMasker.mask_dict(fields)
|
||||
except ImportError:
|
||||
|
||||
@@ -5,7 +5,7 @@ import logging
|
||||
import traceback
|
||||
import os
|
||||
from typing import Any, Dict, Optional
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
logger = None
|
||||
|
||||
|
||||
File renamed without changes.
@@ -1,7 +1,7 @@
|
||||
from douyin.core.douyin_fudai import fudai_analyse
|
||||
|
||||
try:
|
||||
from version import print_version_banner
|
||||
from douyin.core.version import print_version_banner
|
||||
except Exception:
|
||||
print_version_banner = None
|
||||
|
||||
|
||||
@@ -27,12 +27,12 @@ def check_coupon_popup(analyser) -> bool:
|
||||
try:
|
||||
# 使用统一的截图路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
pic = Image.open(pic_path)
|
||||
@@ -198,12 +198,12 @@ def check_shopping_redpacket_popup(analyser) -> bool:
|
||||
try:
|
||||
# 使用统一的截图路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
pic = Image.open(pic_path)
|
||||
|
||||
@@ -95,7 +95,7 @@ def deal_robot_analyse(analyser) -> None:
|
||||
def deal_robot_pic_change_color(analyser) -> None:
|
||||
"""处理人机验证的图片,转为黑白图。"""
|
||||
analyser.cut_pic(*ROBOT_VERIFY, "save", "机器人验证")
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
path = path_config.get_robot_verify_pic_path(save_subdir=True)
|
||||
pic = path
|
||||
|
||||
@@ -253,7 +253,7 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
analyser.operation.get_screenshot(
|
||||
analyser.device_id, use_service=False
|
||||
)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
screenshot_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
|
||||
@@ -17,7 +17,7 @@ from typing import Any, Optional, Dict
|
||||
import json
|
||||
import csv
|
||||
import os
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
from douyin.fudai import douyin_fudai_detail
|
||||
from douyin.reservation import douyin_reservation_logic
|
||||
|
||||
@@ -1046,7 +1046,7 @@ def diagnose_stage_from_current_screen(analyser, trigger_reason="unknown"): # t
|
||||
douyin_screenshot_manager = importlib.import_module(
|
||||
"douyin.handlers.douyin_screenshot_manager"
|
||||
)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
import os
|
||||
from PIL import Image
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class StageHandler:
|
||||
|
||||
# 使用统一的模板路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
assets_dir = path_config.get_assets_dir()
|
||||
except Exception:
|
||||
@@ -107,7 +107,7 @@ class StageHandler:
|
||||
|
||||
# 使用统一的截图路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
screenshot_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
@@ -134,7 +134,7 @@ class StageHandler:
|
||||
if not os.path.exists(screenshot_path):
|
||||
# 尝试从项目根目录的 pic 目录查找
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
alt_path = path_config.get_screenshot_path()
|
||||
if os.path.exists(alt_path) and alt_path != screenshot_path:
|
||||
@@ -247,7 +247,7 @@ class StageHandler:
|
||||
# 保存裁剪的ROI区域
|
||||
# 使用统一的 pic 目录配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
except Exception:
|
||||
|
||||
@@ -26,11 +26,11 @@ class ConfigManager:
|
||||
passed_in_config_path = config_path is not None
|
||||
if config_path is None:
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
default_config_path = path_config.get_config_path()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
default_config_path = path_config.get_config_path()
|
||||
config_path = getattr(analyser, "config_path", default_config_path)
|
||||
|
||||
@@ -67,7 +67,7 @@ class HelperFunctions:
|
||||
"""
|
||||
# 使用统一的截图路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
except (ImportError, ModuleNotFoundError, AttributeError):
|
||||
@@ -197,7 +197,7 @@ class HelperFunctions:
|
||||
def _get_false_positive_file_path() -> str:
|
||||
"""获取误识别记录文件路径"""
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
except (ImportError, ModuleNotFoundError, AttributeError):
|
||||
@@ -365,7 +365,7 @@ class HelperFunctions:
|
||||
|
||||
# 使用统一的截图路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
src = path_config.get_screenshot_path()
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
|
||||
@@ -20,7 +20,7 @@ def preprocess_for_ocr(analyser: Any, cut_pic_name: str) -> str:
|
||||
"""
|
||||
try:
|
||||
from PIL import Image, ImageOps, ImageFilter
|
||||
from path_config import get_cut_pic_path
|
||||
from douyin.core.path_config import get_cut_pic_path
|
||||
except Exception:
|
||||
# 如果 PIL 或 path_config 不可用,回退到原名
|
||||
return cut_pic_name
|
||||
|
||||
@@ -15,7 +15,7 @@ import inspect
|
||||
from typing import Any, Dict
|
||||
|
||||
try:
|
||||
from path_config import get_project_root
|
||||
from douyin.core.path_config import get_project_root
|
||||
except Exception:
|
||||
|
||||
def get_project_root() -> str:
|
||||
|
||||
@@ -17,7 +17,7 @@ import time
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
|
||||
try:
|
||||
from path_config import get_state_dir, ensure_dir
|
||||
from douyin.core.path_config import get_state_dir, ensure_dir
|
||||
except Exception:
|
||||
# 兜底:如果无法导入 path_config,则使用 workspace 相对的 state 目录
|
||||
def get_state_dir() -> str:
|
||||
|
||||
@@ -36,12 +36,12 @@ def is_wrong_coupon_popup(analyser: Any) -> bool:
|
||||
try:
|
||||
# 使用统一的截图路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
path = path_config.get_screenshot_path()
|
||||
|
||||
@@ -228,12 +228,12 @@ def is_wrong_coupon_popup(analyser: Any) -> bool:
|
||||
|
||||
# 使用统一的截图路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
if os.path.exists(pic_path):
|
||||
|
||||
@@ -167,7 +167,7 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
try:
|
||||
if getattr(analyser, "_screenshot_ready_for_ocr", False):
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
@@ -212,7 +212,7 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
|
||||
# 等待截图文件确实存在(最多等待3秒)
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
@@ -239,12 +239,12 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
|
||||
# 使用统一的截图路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
pic_rgb = None
|
||||
@@ -336,7 +336,7 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
except Exception: # pyright: ignore[reportTooBroadExceptionType]
|
||||
# fallback: 将 traceback 写入统一错误日志
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
err_log = path_config.get_error_log_path()
|
||||
with open(err_log, "a", encoding="utf-8") as ef:
|
||||
|
||||
@@ -207,7 +207,7 @@ def read_live_room_title_core(
|
||||
else:
|
||||
# 检查是否有可用的截图文件
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
|
||||
@@ -12,7 +12,7 @@ import logging
|
||||
import re
|
||||
import os
|
||||
import json
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
|
||||
def validate_fudai_detail(detail: Tuple, analyser: Any = None) -> Tuple[bool, str]:
|
||||
|
||||
@@ -63,11 +63,11 @@ def create_actions_log_viewer(
|
||||
"""刷新行为日志:读取 logs/actions.log 的尾部若干行,在 GUI 中展示关键行为日志(支持简单关键字筛选)。"""
|
||||
# 使用统一的路径配置
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
path = path_config.get_actions_log_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
path = path_config.get_actions_log_path()
|
||||
|
||||
try:
|
||||
|
||||
@@ -9,7 +9,7 @@ from datetime import datetime, timedelta
|
||||
import re
|
||||
|
||||
try:
|
||||
from path_config import get_error_log_path # type: ignore[assignment]
|
||||
from douyin.core.path_config import get_error_log_path # type: ignore[assignment]
|
||||
HAS_LOGGING = True
|
||||
except ImportError:
|
||||
# 如果导入失败,提供占位符函数
|
||||
|
||||
+26
-26
@@ -32,7 +32,7 @@ from gui.gui_core import (
|
||||
read_config,
|
||||
write_config,
|
||||
)
|
||||
from path_config import get_logs_dir
|
||||
from douyin.core.path_config import get_logs_dir
|
||||
from gui.components.mapping_table import create_mapping_tab
|
||||
|
||||
# 导入日志颜色配置模块
|
||||
@@ -188,7 +188,7 @@ def main():
|
||||
# 获取日志文件路径配置
|
||||
log_path = cfg.get("log_unified_path") or "logs/unified.log"
|
||||
if not os.path.isabs(log_path):
|
||||
from path_config import PROJECT_ROOT
|
||||
from douyin.core.path_config import PROJECT_ROOT
|
||||
|
||||
log_path = os.path.join(PROJECT_ROOT, log_path)
|
||||
|
||||
@@ -3037,7 +3037,7 @@ def main():
|
||||
# 在后台线程中执行截图和OCR识别,避免阻塞GUI
|
||||
def screenshot_thread():
|
||||
try:
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
|
||||
# 使用模块级别导入的 Image 与 os,避免重复导入导致 Pylance 警告
|
||||
|
||||
@@ -3059,12 +3059,12 @@ def main():
|
||||
|
||||
# 读取截图以获取实际尺寸
|
||||
try:
|
||||
from path_config import get_screenshot_path
|
||||
from douyin.core.path_config import get_screenshot_path
|
||||
|
||||
screenshot_path = get_screenshot_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
screenshot_path = path_config.get_screenshot_path()
|
||||
if not os.path.exists(screenshot_path):
|
||||
@@ -3338,11 +3338,11 @@ def main():
|
||||
if show_screenshot_var.get():
|
||||
try:
|
||||
try:
|
||||
from path_config import get_screenshot_path
|
||||
from douyin.core.path_config import get_screenshot_path
|
||||
|
||||
screenshot_path = get_screenshot_path()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
screenshot_path = path_config.get_screenshot_path()
|
||||
|
||||
@@ -3498,11 +3498,11 @@ def main():
|
||||
# update image
|
||||
try:
|
||||
try:
|
||||
from path_config import get_screenshot_path
|
||||
from douyin.core.path_config import get_screenshot_path
|
||||
|
||||
screenshot_path = get_screenshot_path()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
screenshot_path = path_config.get_screenshot_path()
|
||||
|
||||
@@ -3862,12 +3862,12 @@ def main():
|
||||
preview_top.pack(fill=X, padx=10, pady=10)
|
||||
|
||||
try:
|
||||
from path_config import get_pic_dir
|
||||
from douyin.core.path_config import get_pic_dir
|
||||
|
||||
images_dir = get_pic_dir()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
images_dir = path_config.get_pic_dir()
|
||||
|
||||
@@ -4958,12 +4958,12 @@ def main():
|
||||
|
||||
def refresh_reservations():
|
||||
try:
|
||||
from path_config import get_reservations_path
|
||||
from douyin.core.path_config import get_reservations_path
|
||||
|
||||
path = get_reservations_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
path = path_config.get_reservations_path()
|
||||
try:
|
||||
@@ -5233,12 +5233,12 @@ def main():
|
||||
|
||||
def refresh_high_value_rooms():
|
||||
try:
|
||||
from path_config import get_high_value_rooms_path
|
||||
from douyin.core.path_config import get_high_value_rooms_path
|
||||
|
||||
path = get_high_value_rooms_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
path = path_config.get_high_value_rooms_path()
|
||||
try:
|
||||
@@ -5322,13 +5322,13 @@ def main():
|
||||
"""读取 logs/actions.log 的尾部若干行,在 GUI 中展示关键行为日志(支持简单关键字筛选)。"""
|
||||
# 使用统一的路径配置
|
||||
try:
|
||||
from path_config import get_actions_log_path
|
||||
from douyin.core.path_config import get_actions_log_path
|
||||
|
||||
path = get_actions_log_path()
|
||||
except Exception:
|
||||
# 回退到旧路径(向后兼容)
|
||||
# 修正路径:GUI应该读取根目录的logs/actions.log
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
path = path_config.get_actions_log_path()
|
||||
try:
|
||||
@@ -5582,11 +5582,11 @@ def main():
|
||||
def scan_win_images():
|
||||
"""扫描中奖截图目录"""
|
||||
try:
|
||||
from path_config import get_pic_dir
|
||||
from douyin.core.path_config import get_pic_dir
|
||||
|
||||
pic_dir = get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
|
||||
@@ -5697,11 +5697,11 @@ def main():
|
||||
def open_win_folder():
|
||||
"""打开中奖截图目录"""
|
||||
try:
|
||||
from path_config import get_pic_dir
|
||||
from douyin.core.path_config import get_pic_dir
|
||||
|
||||
pic_dir = get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
|
||||
@@ -5735,11 +5735,11 @@ def main():
|
||||
def load_false_positives():
|
||||
"""加载误识别记录"""
|
||||
try:
|
||||
from path_config import get_pic_dir
|
||||
from douyin.core.path_config import get_pic_dir
|
||||
|
||||
pic_dir = get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
|
||||
@@ -5767,11 +5767,11 @@ def main():
|
||||
def save_false_positives():
|
||||
"""保存误识别记录"""
|
||||
try:
|
||||
from path_config import get_pic_dir
|
||||
from douyin.core.path_config import get_pic_dir
|
||||
|
||||
pic_dir = get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
|
||||
@@ -5849,7 +5849,7 @@ def main():
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
from version import print_version_banner
|
||||
from douyin.core.version import print_version_banner
|
||||
|
||||
print_version_banner("gui_app")
|
||||
except Exception:
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import time
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
CONFIG_PATH = path_config.get_config_path()
|
||||
|
||||
|
||||
+4
-4
@@ -17,7 +17,7 @@ project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if project_root not in sys.path:
|
||||
sys.path.insert(0, project_root)
|
||||
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
BASE_DIR = path_config.PROJECT_ROOT
|
||||
CONFIG_PATH = path_config.get_config_path()
|
||||
@@ -1359,7 +1359,7 @@ class ProcRunner:
|
||||
# 启动时自动截图
|
||||
if device_id:
|
||||
try:
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
|
||||
ops = underlying_operations()
|
||||
self._append_log(f"[启动] 自动截图: device={device_id}")
|
||||
@@ -2203,7 +2203,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
body = self._read_json()
|
||||
device_id = str(body.get("device_id") or "").strip()
|
||||
try:
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
|
||||
ops = underlying_operations()
|
||||
result = ops.get_screenshot(device_id, use_service=False)
|
||||
@@ -2249,7 +2249,7 @@ def main() -> int:
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
from version import print_version_banner
|
||||
from douyin.core.version import print_version_banner
|
||||
|
||||
print_version_banner("web_gui")
|
||||
except Exception:
|
||||
|
||||
@@ -19,7 +19,7 @@ from .screenshot_operations import (
|
||||
|
||||
# 从原文件导入以保持向后兼容
|
||||
# TODO: 逐步迁移后改为从子模块导入
|
||||
from Underlying_Operations import (
|
||||
from douyin.core.underlying_operations import (
|
||||
_safe_replace_file,
|
||||
_ensure_parent_dir,
|
||||
_mirror_screenshot_to_external,
|
||||
|
||||
@@ -9,7 +9,7 @@ from typing import Any, Optional
|
||||
|
||||
# 临时导入:从原文件导入,后续会逐步迁移
|
||||
# TODO: 迁移完成后,移除此导入并在此文件中实现
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
|
||||
# 导出设备操作相关方法
|
||||
# TODO: 实现这些函数后添加到__all__列表中
|
||||
|
||||
@@ -9,7 +9,7 @@ from typing import Any, Optional, Tuple
|
||||
|
||||
# 临时导入:从原文件导入,后续会逐步迁移
|
||||
# TODO: 迁移完成后,移除此导入并在此文件中实现
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
|
||||
# 导出图像处理相关方法
|
||||
# TODO: 实现这些函数后添加到__all__列表中
|
||||
|
||||
@@ -185,7 +185,7 @@ def _ensure_ocr():
|
||||
def analyse_pic_word(picname, change_color=0, pic_path=None):
|
||||
"""文字OCR识别(向后兼容接口)"""
|
||||
# 使用全局复用的 underlying_operations 实例,避免每次调用都初始化 OCR(耗时)
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
global _UNDERLYING_OPS_SINGLETON # type: ignore[name-defined]
|
||||
try:
|
||||
_UNDERLYING_OPS_SINGLETON # type: ignore[name-defined]
|
||||
@@ -197,7 +197,7 @@ def analyse_pic_word(picname, change_color=0, pic_path=None):
|
||||
def analyse_pic_digits(picname, change_color=1, pic_path=None):
|
||||
"""数字OCR识别(向后兼容接口)"""
|
||||
# 使用全局复用的 underlying_operations 实例,避免每次调用都初始化 OCR(耗时)
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
global _UNDERLYING_OPS_SINGLETON # type: ignore[name-defined]
|
||||
try:
|
||||
_UNDERLYING_OPS_SINGLETON # type: ignore[name-defined]
|
||||
@@ -209,7 +209,7 @@ def analyse_pic_digits(picname, change_color=1, pic_path=None):
|
||||
def extract_ocr_content(content=[], return_confidence=False):
|
||||
"""提取OCR内容(向后兼容接口)"""
|
||||
# 使用全局复用的 underlying_operations 实例
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
global _UNDERLYING_OPS_SINGLETON # type: ignore[name-defined]
|
||||
try:
|
||||
_UNDERLYING_OPS_SINGLETON # type: ignore[name-defined]
|
||||
|
||||
@@ -13,7 +13,7 @@ import time
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from Underlying_Operations import _safe_replace_file, _mirror_screenshot_to_external
|
||||
from douyin.core.underlying_operations import _safe_replace_file, _mirror_screenshot_to_external
|
||||
|
||||
# 日志节流:当后台服务不可用并回退到直接截图时,避免每次都打印相同的日志
|
||||
_last_service_fallback_log_ts: float = 0.0
|
||||
@@ -87,7 +87,7 @@ class ScreenshotOperations:
|
||||
direct_start = time.time()
|
||||
if path == "pic":
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
out_dir = path_config.get_pic_dir()
|
||||
except Exception: # type: ignore
|
||||
# 回退到旧路径(向后兼容)
|
||||
@@ -305,10 +305,10 @@ class ScreenshotOperations:
|
||||
"""
|
||||
# 搜索目录优先级
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
pic_dir = path_config.get_pic_dir()
|
||||
|
||||
search_dirs = []
|
||||
@@ -340,7 +340,7 @@ class ScreenshotOperations:
|
||||
"""裁剪图片:保持与原 fudai1.cut_pic 相同的坐标语义(1080x2400 基准)。"""
|
||||
# 这里应该实现图片裁剪逻辑
|
||||
# 暂时从原文件导入以保持功能
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
instance = underlying_operations()
|
||||
return instance.cut_pic(left_up, right_down, target, name)
|
||||
|
||||
@@ -348,7 +348,7 @@ class ScreenshotOperations:
|
||||
"""保存奖励图片"""
|
||||
# 这里应该实现奖励图片保存逻辑
|
||||
# 暂时从原文件导入以保持功能
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
instance = underlying_operations()
|
||||
return instance.save_reward_pic(device_id)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import threading
|
||||
import time
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
from operations.screenshot_operations import ScreenshotOperations
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import threading
|
||||
import time
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
from operations.screenshot_operations import ScreenshotOperations
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
from douyin.logging import action_logger, douyin_logging_wrapper
|
||||
from douyin.core.douyin_fudai import fudai_analyse
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
|
||||
def safe_repr(obj):
|
||||
|
||||
@@ -16,11 +16,11 @@ if sys.platform == "win32":
|
||||
pass
|
||||
|
||||
try:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
CONFIG_PATH = path_config.get_config_path()
|
||||
except Exception:
|
||||
import path_config
|
||||
from douyin.core import path_config
|
||||
|
||||
CONFIG_PATH = path_config.get_config_path()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from Underlying_Operations import underlying_operations
|
||||
from douyin.core.underlying_operations import underlying_operations
|
||||
import time
|
||||
|
||||
op = underlying_operations()
|
||||
|
||||
Reference in new issue
Block a user