fix(code-quality): 修复 NameError 风险和死代码清理
- detect_by_template.py: 添加缺失的 os 和 path_config 导入 - join_decision.py: 添加缺失的 is_watch_task_fudai 导入 - read_once.py: 添加缺失的 Optional 类型导入 - fudai_detail_validator.py: 使用 extract_2digits 做更健壮的数字解析 - screenshot_manager: 移除未使用的导入和死代码 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e62314fa25
commit
ca00258bf3
8 files changed
+25
-23
No files matched your search
@@ -6,7 +6,7 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import time
|
||||
from typing import Any, Dict, Tuple
|
||||
from typing import Any, Dict, Optional, Tuple
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
@@ -201,8 +201,14 @@ def validate_fudai_detail(detail: Tuple, analyser: Any = None) -> Tuple[bool, st
|
||||
).strip()
|
||||
if countdown_mm_raw and countdown_ss_raw:
|
||||
try:
|
||||
mm = int(countdown_mm_raw)
|
||||
ss = int(countdown_ss_raw)
|
||||
from douyin.utils.time_utils import extract_2digits
|
||||
|
||||
mm_str = extract_2digits(countdown_mm_raw)
|
||||
ss_str = extract_2digits(countdown_ss_raw)
|
||||
if not mm_str or not ss_str:
|
||||
return False, "countdown_mm_ss_not_numeric"
|
||||
mm = int(mm_str)
|
||||
ss = int(ss_str)
|
||||
if mm < 0 or mm > 59 or ss < 0 or ss > 59:
|
||||
return False, "countdown_mm_ss_invalid_range"
|
||||
# 如果有倒计时元组,验证是否一致
|
||||
|
||||
@@ -10,7 +10,7 @@ import re
|
||||
import time
|
||||
from typing import Any, Tuple
|
||||
|
||||
from .helpers import _is_short_countdown_text
|
||||
from .helpers import _is_short_countdown_text, is_watch_task_fudai
|
||||
from .should_skip import should_skip_fudai_by_config
|
||||
|
||||
|
||||
|
||||
@@ -7,11 +7,14 @@ from __future__ import annotations
|
||||
|
||||
# pylint: disable=E1101
|
||||
|
||||
import os
|
||||
import time
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from douyin.core import path_config
|
||||
|
||||
|
||||
def detect_by_template(analyser, rx: int, pic: Image.Image, region: Dict) -> Optional[int]:
|
||||
"""使用模板匹配在指定区域查找福袋图标(优化版:多方法+预处理)
|
||||
|
||||
@@ -26,8 +26,6 @@ from ._common import (
|
||||
_debug_save_queue,
|
||||
_debug_save_shutdown_event,
|
||||
_debug_save_worker_lock,
|
||||
_LOGGER,
|
||||
_mgr_log,
|
||||
)
|
||||
from . import _common as _state
|
||||
from .paths import ensure_debug_captures_dir
|
||||
@@ -353,8 +351,3 @@ def _ensure_debug_save_worker_started() -> None:
|
||||
t = threading.Thread(target=_debug_save_loop, name="debug-save-worker", daemon=True)
|
||||
t.start()
|
||||
_state._debug_save_worker_started = True
|
||||
|
||||
|
||||
# 注册 atexit 清理函数(仅注册一次)
|
||||
import atexit
|
||||
atexit.register(shutdown_debug_save_worker)
|
||||
@@ -4,7 +4,6 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
from douyin.core import path_config
|
||||
|
||||
@@ -11,6 +11,8 @@ from datetime import datetime
|
||||
|
||||
from douyin.core import path_config
|
||||
|
||||
from ._common import _mgr_log
|
||||
|
||||
|
||||
def get_ocr_dir() -> str:
|
||||
"""获取OCR目录路径"""
|
||||
|
||||
@@ -8,12 +8,9 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional, Tuple
|
||||
from typing import Optional, Tuple
|
||||
|
||||
import logging
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
@@ -21,17 +18,22 @@ from PIL import Image, ImageDraw, ImageFont
|
||||
from douyin.core import path_config
|
||||
|
||||
from ._common import (
|
||||
_async_save_counters_lock,
|
||||
_debug_save_queue,
|
||||
_LOGGER,
|
||||
_mgr_log,
|
||||
_SKIP_DEBUG_SAVE_IN_HOTLOOPS,
|
||||
)
|
||||
from . import _common as _state
|
||||
from .cleanup import (
|
||||
_OPERATION_TYPE_CN,
|
||||
_PICNAME_CN,
|
||||
_STEP_CN,
|
||||
_EXTRA_INFO_KEY_CN,
|
||||
cleanup_debug_captures,
|
||||
count_debug_captures_files,
|
||||
)
|
||||
from .paths import (
|
||||
ensure_debug_captures_dir,
|
||||
get_category_for_picname,
|
||||
get_debug_captures_dir,
|
||||
get_debug_captures_base_dir,
|
||||
)
|
||||
from .async_save import _ensure_debug_save_worker_started
|
||||
|
||||
@@ -726,6 +728,3 @@ def save_debug_image( # type: ignore
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
# 结束 save_debug_image 的主逻辑,返回 None 表示保存失败
|
||||
return None
|
||||
Reference in new issue
Block a user