refactor: Remove deprecated files and enhance configuration settings
- Deleted outdated markdown files and scripts related to previous implementations. - Updated `config.json` to adjust thresholds and settings for 福袋 detection and reservation handling. - Improved logging and error handling across various modules for better monitoring and user experience. - Introduced a new screenshot management module to facilitate real-time operation and success tracking. - Enhanced GUI elements to support new configuration options and improve usability.
This commit is contained in:
1 parent
8b47b506d6
commit
47e6b016c5
31 files changed
+2257
-7371
No files matched your search
+62
-19
@@ -327,11 +327,11 @@ class underlying_operations:
|
||||
return dictdevice[num]
|
||||
|
||||
def _find_pic_path(self, picname: str, for_reading: bool = True) -> Optional[str]:
|
||||
"""查找图片路径,支持新旧位置(向后兼容)
|
||||
"""查找图片路径,支持新旧位置(向后兼容),并按分类组织
|
||||
|
||||
Args:
|
||||
picname: 图片名称(不含扩展名),如 '直播广场', '福袋内容'
|
||||
for_reading: True=读取(支持新旧位置),False=写入(使用新位置)
|
||||
for_reading: True=读取(支持新旧位置),False=写入(使用新位置+分类目录)
|
||||
|
||||
Returns:
|
||||
图片的完整路径,如果找不到且for_reading=True则返回None
|
||||
@@ -345,21 +345,33 @@ class underlying_operations:
|
||||
path = os.path.join(pic_base, f'{picname}.png')
|
||||
return path if (os.path.exists(path) or not for_reading) else None
|
||||
|
||||
# OCR图片文件:优先查找新位置(ocr/),然后查找旧位置(根目录)
|
||||
# OCR图片文件:按分类组织到子目录
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
category = douyin_screenshot_manager.get_category_for_picname(picname)
|
||||
except Exception:
|
||||
category = "others"
|
||||
|
||||
if for_reading:
|
||||
# 读取:先查新位置,再查旧位置(向后兼容)
|
||||
new_path = os.path.join(pic_base, 'ocr', f'{picname}.png')
|
||||
if os.path.exists(new_path):
|
||||
return new_path
|
||||
old_path = os.path.join(pic_base, f'{picname}.png')
|
||||
if os.path.exists(old_path):
|
||||
return old_path
|
||||
# 读取:先查分类目录,再查旧位置(向后兼容)
|
||||
# 1. 新位置(分类目录)
|
||||
category_path = os.path.join(pic_base, 'ocr', category, f'{picname}.png')
|
||||
if os.path.exists(category_path):
|
||||
return category_path
|
||||
# 2. 旧位置(ocr根目录)
|
||||
old_ocr_path = os.path.join(pic_base, 'ocr', f'{picname}.png')
|
||||
if os.path.exists(old_ocr_path):
|
||||
return old_ocr_path
|
||||
# 3. 更旧的位置(pic根目录)
|
||||
old_root_path = os.path.join(pic_base, f'{picname}.png')
|
||||
if os.path.exists(old_root_path):
|
||||
return old_root_path
|
||||
return None
|
||||
else:
|
||||
# 写入:使用新位置,确保目录存在
|
||||
ocr_dir = os.path.join(pic_base, 'ocr')
|
||||
os.makedirs(ocr_dir, exist_ok=True)
|
||||
return os.path.join(ocr_dir, f'{picname}.png')
|
||||
# 写入:使用分类目录,确保目录存在
|
||||
category_dir = os.path.join(pic_base, 'ocr', category)
|
||||
os.makedirs(category_dir, exist_ok=True)
|
||||
return os.path.join(category_dir, f'{picname}.png')
|
||||
|
||||
def get_screenshot(self, device_id, path='pic'):
|
||||
"""截图3个adb命令需要2S左右的时间"""
|
||||
@@ -653,7 +665,16 @@ class underlying_operations:
|
||||
if left < 0 or top < 0 or right > width or bottom > height or left >= right or top >= bottom:
|
||||
raise ValueError(f"裁剪坐标无效: left_up={left_up}, right_down={right_down}, image_size={pic.size}")
|
||||
|
||||
pic.crop((left, top, right, bottom)).save(cut_pic_path)
|
||||
cropped_img = pic.crop((left, top, right, bottom))
|
||||
cropped_img.save(cut_pic_path)
|
||||
|
||||
# 双截图记录:保存实时操作截图
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
douyin_screenshot_manager.save_latest_attempt(cropped_img, operation_type="cut_pic")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return True
|
||||
|
||||
else:
|
||||
@@ -857,17 +878,32 @@ class underlying_operations:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 双截图记录:无论成功与否,都保存实时操作截图
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
# 使用预处理后的图片(实际用于OCR的图片)
|
||||
img_for_attempt = img2 if (img2 is not None and text2 and text2.strip()) else img1
|
||||
douyin_screenshot_manager.save_latest_attempt(img_for_attempt, operation_type="ocr")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 如果OCR识别成功(返回非空文本),保存一份图片到ocr文件夹(与cut_pic保存的图片区分开)
|
||||
if text and text.strip() and picname:
|
||||
try:
|
||||
# 使用_find_pic_path获取ocr文件夹路径(写入模式)
|
||||
# 使用分类目录保存成功截图
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
category = douyin_screenshot_manager.get_category_for_picname(picname)
|
||||
except Exception:
|
||||
category = "others"
|
||||
|
||||
base_dir = os.path.dirname(__file__)
|
||||
pic_base = os.path.join(base_dir, 'pic')
|
||||
ocr_dir = os.path.join(pic_base, 'ocr')
|
||||
os.makedirs(ocr_dir, exist_ok=True)
|
||||
category_dir = os.path.join(pic_base, 'ocr', category)
|
||||
os.makedirs(category_dir, exist_ok=True)
|
||||
|
||||
# 保存文件名:{picname}_success.png,与cut_pic保存的{picname}.png区分开
|
||||
success_path = os.path.join(ocr_dir, f'{picname}_success.png')
|
||||
success_path = os.path.join(category_dir, f'{picname}_success.png')
|
||||
|
||||
# 保存识别成功时的图片(使用预处理后的图片,即实际用于OCR的图片)
|
||||
try:
|
||||
@@ -877,6 +913,13 @@ class underlying_operations:
|
||||
else:
|
||||
# 否则保存预处理后的图片(img1)
|
||||
img_to_save = img1
|
||||
|
||||
# 双截图记录:保存成功识别存档截图
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
douyin_screenshot_manager.save_last_success(img_to_save, operation_type="ocr")
|
||||
except Exception:
|
||||
pass
|
||||
img_to_save.save(success_path)
|
||||
except Exception:
|
||||
# 如果保存预处理后的图片失败,保存原始图片
|
||||
|
||||
Reference in new issue
Block a user