diff --git a/src/tree.py b/src/tree.py index e64094557022fcce0891ee680c4850284715e8f4..b8cfb5f8ae0913e84c9e5581359a7619f4b93369 100644 --- a/src/tree.py +++ b/src/tree.py @@ -15,8 +15,9 @@ formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) logger.addHandler(handler) + def load_json(p): - with open(p, 'r') as f: + with open(p, 'r', encoding='utf-8') as f: return json.loads(f.read()) @@ -100,11 +101,13 @@ class TreeWalker: for index, chapter in enumerate(level_node["children"]): chapter_title = list(chapter.keys())[0] chapter_node = list(chapter.values())[0] - chapter_path = os.path.join(level_path, f"{index+1}.{chapter_title}") + chapter_path = os.path.join( + level_path, f"{index+1}.{chapter_title}") self.load_sections(chapter_path, chapter_node) for index, section_node in enumerate(chapter_node["children"]): section_title = list(section_node.keys())[0] - full_path = os.path.join(chapter_path, f"{index}.{section_title}") + full_path = os.path.join( + chapter_path, f"{index}.{section_title}") if os.path.isdir(full_path): self.ensure_exercises(full_path) @@ -230,8 +233,8 @@ class TreeWalker: config = { "node_id": self.gen_node_id(), "keywords": [], - "children":[], - "export":[] + "children": [], + "export": [] } dump_json(config_path, config, exist_ok=True, override=True) else: @@ -295,4 +298,3 @@ class TreeWalker: if "exercise_id" not in exercise: exercise["exercise_id"] = uuid.uuid4().hex dump_json(full_name, exercise) -