From 823cb1cbaf548ce596e52dcdfd143053277996b2 Mon Sep 17 00:00:00 2001 From: Weiduhuo <1281586535@qq.com> Date: Thu, 2 Nov 2023 21:57:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20'config.json'=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9C=AA=E6=88=90=E5=8A=9F=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/config.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/config.py b/utils/config.py index 105acfd7..c1a03cc2 100644 --- a/utils/config.py +++ b/utils/config.py @@ -92,9 +92,9 @@ def modify_json_file(filename:str, key:str, value:Any) -> dict: data: 修改后的json字典 """ # 先读,再写 - data, file_path = read_json_file(filename, path=True) + data = read_json_file(filename) data[key] = value - return rewrite_json_file(file_path, data) + return rewrite_json_file(filename, data) def rewrite_json_file(filename:str, data:dict) -> dict: @@ -108,6 +108,8 @@ def rewrite_json_file(filename:str, data:dict) -> dict: data: 修改后的json字典 """ file_path = normalize_file_path(filename) + if file_path is None: + file_path = filename # 原文件不存在,则新建 try: with open(file_path, "wb") as f: f.write(orjson.dumps(data, option=orjson.OPT_PASSTHROUGH_DATETIME | orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_INDENT_2)) From bf8c21de1392d903e9409426ff598486fa41a45e Mon Sep 17 00:00:00 2001 From: Weiduhuo <1281586535@qq.com> Date: Thu, 2 Nov 2023 21:58:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=E6=9C=89?= =?UTF-8?q?=E5=85=B3=E9=81=97=E5=99=A8=E6=A8=A1=E5=9D=97=E7=9A=84=E9=9D=9E?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/config.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/utils/config.py b/utils/config.py index c1a03cc2..30ce5346 100644 --- a/utils/config.py +++ b/utils/config.py @@ -59,25 +59,10 @@ def read_json_file(filename: str, path=False, schema:dict=None) -> dict: else: return data else: - if filename in [RELIC_FILE_NAME, LOADOUT_FILE_NAME, TEAM_FILE_NAME]: - init_json_file(filename) - return read_json_file(filename, path) if path: return {}, filename else: return {} - - -def init_json_file(filename: str): - """ - 说明: - 初始化json文件为空字典 - 参数: - :param filename: 文件名称 - """ - with open(filename, "wb") as f: - log.info(_(f"{filename} 文件初始化")) - f.write(orjson.dumps({}, option = orjson.OPT_PASSTHROUGH_DATETIME | orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_INDENT_2)) def modify_json_file(filename:str, key:str, value:Any) -> dict: