diff --git a/README.md b/README.md index 699538339e1822421f995b9366fe9cbcbb8790aa..6fd4b7f3f99835a5cf8edab48810faf821339f2a 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,7 @@ CSDN 技能树结构(章节、元信息、习题)解释器,支持技能树 - 捕获 json 文件编码错误 ### 0.0.6 - - 为 `keywords_must` 和 `keywords_forbid` 的读取操作添加默认值 \ No newline at end of file + - 为 `keywords_must` 和 `keywords_forbid` 的读取操作添加默认值 + +### 0.0.7 + - 为 config.json 添加默认的 `keywords_must` 和 `keywords_forbid` 空列表 \ No newline at end of file diff --git a/setup.py b/setup.py index f1b28b9b5d944f215d474349aae3f93f7159549e..c76ae576d45c18e799971d3b894a2c9b7efcd275 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ this_directory = Path(__file__).parent long_description = (this_directory / "README.md").read_text() setup(name="skill-tree-parser", - version="0.0.6", + version="0.0.7", description="CSDN Skill Tree Parser", long_description=long_description, long_description_content_type='text/markdown', diff --git a/src/skill_tree/tree.py b/src/skill_tree/tree.py index e53153f087b42ae5c5a574a10305dc8d82a2b45f..a9386ccb8a53c70bc6bbc445d428bc1a837abcac 100644 --- a/src/skill_tree/tree.py +++ b/src/skill_tree/tree.py @@ -64,7 +64,9 @@ def dump_json(p, j, exist_ok=False, override=False): def ensure_config(path): config_path = os.path.join(path, "config.json") if not os.path.exists(config_path): - node = {"keywords": []} + node = {"keywords": [], + "keywords_must": [], + "keywords_forbid": []} dump_json(config_path, node, exist_ok=True, override=False) return node else: @@ -121,7 +123,7 @@ class TreeWalker: root = self.load_root() root_node = { "node_id": root["node_id"], - "keywords": root["keywords"], + "keywords": root.get("keywords", []), "children": [], "keywords_must": root.get("keywords_must", []), "keywords_forbid": root.get("keywords_forbid", []) @@ -282,7 +284,9 @@ class TreeWalker: "node_id": self.gen_node_id(), "keywords": [], "children": [], - "export": [] + "export": [], + "keywords_must": [], + "keywords_forbid": [] } dump_json(config_path, config, exist_ok=True, override=True) else: @@ -343,7 +347,7 @@ class TreeWalker: result = { name: { "node_id": config["node_id"], - "keywords": config["keywords"], + "keywords": config.get("keywords", []), "children": config.get("children", []), "keywords_must": config.get("keywords_must", []), "keywords_forbid": config.get("keywords_forbid", [])