diff --git a/py-src/config.py b/py-src/config.py index 876c471..2fc4395 100644 --- a/py-src/config.py +++ b/py-src/config.py @@ -1,16 +1,41 @@ import os +import re + class Config: - RANGE_NUM: int = 100 - WORK_PATH = "E:/商品资料汇总/商品资料(1151-1200)" - # WORK_PATH = "C:/Users/Administrator/Desktop/测试" - + RANGE_NUM: int = 0 + WORK_PATH = "" INPUT_PATH = "" - # INPUT_PATH = "E:/商品资料汇总/商品资料(1101-1150)/ppt1135-世界海洋日" + + @staticmethod + def load_config(): + # 构建 config/index.js 的相对路径 + config_file_path = os.path.join( + os.path.dirname(__file__), "..", "config", "index.js" + ) + with open(config_file_path, "r", encoding="utf-8") as file: + content = file.read() + # 移除注释行 + uncommented_content = re.sub(r"//.*", "", content) + input_dir_match = re.search( + r'inputDir:\s*["\']?(.*?)["\']?\s*,', uncommented_content + ) + directory_path_match = re.search( + r'directoryPath:\s*["\']?(.*?)["\']?\s*,', uncommented_content + ) + range_num_match = re.search( + r'rangeNum:\s*["\']?(.*?)["\']?\s*,', uncommented_content + ) + if input_dir_match: + Config.INPUT_PATH = input_dir_match.group(1) + if directory_path_match: + Config.WORK_PATH = directory_path_match.group(1) + if range_num_match: + Config.RANGE_NUM = range_num_match.group(1) @staticmethod def get_latest_folder(base_directory): - if Config.INPUT_PATH is not None and Config.INPUT_PATH != "": + if Config.INPUT_PATH: return Config.INPUT_PATH folders = [ os.path.join(base_directory, d) @@ -21,3 +46,6 @@ class Config: return None latest_folder = max(folders, key=os.path.getctime) # 获取最新创建的文件夹 return latest_folder + + +Config.load_config() diff --git a/py-src/ppt_to_img.py b/py-src/ppt_to_img.py index c4d9a32..a7a1dd1 100644 --- a/py-src/ppt_to_img.py +++ b/py-src/ppt_to_img.py @@ -36,7 +36,7 @@ def batch_convert_ppt_to_png(directory, output_directory): # 遍历指定目录中的所有PPT和PPTX文件 for filename in os.listdir(directory): if filename.endswith(".ppt") or filename.endswith(".pptx"): - if conversion_count >= Config.RANGE_NUM: + if Config.RANGE_NUM and conversion_count >= Config.RANGE_NUM: print("已达到最大转换限制。") break # 如果达到最大转换次数,则停止