From b9809d0dc2153152f27666fb40363e9669b907df Mon Sep 17 00:00:00 2001 From: LCJ-MinYa <1049468118@qq.com> Date: Mon, 14 Oct 2024 11:17:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20python=E9=85=8D=E7=BD=AE=E4=BB=8Enode?= =?UTF-8?q?=20config=E9=87=8C=E9=9D=A2=E5=8E=BB=E5=8F=96=EF=BC=8C=E8=BF=99?= =?UTF-8?q?=E6=A0=B7=E5=8F=AA=E9=9C=80=E8=A6=81=E7=BB=B4=E6=8A=A4=E4=B8=80?= =?UTF-8?q?=E5=A4=84=E5=8D=B3=E5=8F=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py-src/config.py | 40 ++++++++++++++++++++++++++++++++++------ py-src/ppt_to_img.py | 2 +- 2 files changed, 35 insertions(+), 7 deletions(-) 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 # 如果达到最大转换次数,则停止