feat: python配置从node config里面去取,这样只需要维护一处即可

main
LCJ-MinYa 1 year ago
parent c8fdb76b34
commit b9809d0dc2

@ -1,16 +1,41 @@
import os import os
import re
class Config:
RANGE_NUM: int = 100
WORK_PATH = "E:/商品资料汇总/商品资料(1151-1200)"
# WORK_PATH = "C:/Users/Administrator/Desktop/测试"
class Config:
RANGE_NUM: int = 0
WORK_PATH = ""
INPUT_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 @staticmethod
def get_latest_folder(base_directory): 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 return Config.INPUT_PATH
folders = [ folders = [
os.path.join(base_directory, d) os.path.join(base_directory, d)
@ -21,3 +46,6 @@ class Config:
return None return None
latest_folder = max(folders, key=os.path.getctime) # 获取最新创建的文件夹 latest_folder = max(folders, key=os.path.getctime) # 获取最新创建的文件夹
return latest_folder return latest_folder
Config.load_config()

@ -36,7 +36,7 @@ def batch_convert_ppt_to_png(directory, output_directory):
# 遍历指定目录中的所有PPT和PPTX文件 # 遍历指定目录中的所有PPT和PPTX文件
for filename in os.listdir(directory): for filename in os.listdir(directory):
if filename.endswith(".ppt") or filename.endswith(".pptx"): 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("已达到最大转换限制。") print("已达到最大转换限制。")
break # 如果达到最大转换次数,则停止 break # 如果达到最大转换次数,则停止

Loading…
Cancel
Save