From c9436a4a1dc4d81a42b583fbe887fed4e0be6141 Mon Sep 17 00:00:00 2001 From: fengbohan <1953356163@qq.com> Date: Thu, 17 Aug 2023 09:53:08 +0800 Subject: [PATCH] add_func: support yaml --- config.yaml | 1 + gen_word.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 config.yaml diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..15403f5 --- /dev/null +++ b/config.yaml @@ -0,0 +1 @@ +user_name: 冯博涵 diff --git a/gen_word.py b/gen_word.py index e8881f5..b65b0df 100644 --- a/gen_word.py +++ b/gen_word.py @@ -8,20 +8,26 @@ import win32com from win32com.client import Dispatch, constants import os import sys +import ruamel.yaml as yaml class WEEK_REPORT: file_name = "" pre_file_name = "" pre_str = "" str = "" + user_name = "" __word = "" __doc = "" def __init__(self): + with open("config.yaml", "r", encoding="UTF-8") as f1: + data = yaml.safe_load(f1) + print("config.yaml: {}".format(data)) + self.user_name = data["user_name"] self.get_name() def get_name(self): - self.file_name = "{}WW{}周工作报告_冯博涵.doc".format(time.strftime('%Y'), time.strftime('%W')) - self.pre_file_name = "{}WW{}周工作报告_冯博涵.doc".format(time.strftime('%Y'), str(int(time.strftime('%W'))-1)) + self.file_name = "{}WW{}周工作报告_{}.doc".format(time.strftime('%Y'), time.strftime('%W'), self.user_name) + self.pre_file_name = "{}WW{}周工作报告_{}.doc".format(time.strftime('%Y'), str(int(time.strftime('%W'))-1), self.user_name) print("pre file name: {}; \nnew file name: {};".format(self.pre_file_name, self.file_name)) if(os.path.isfile(self.file_name)==True): print("{} is already exist.".format(self.file_name))