From 6c18cb8dbef4b163b3a87e2a55e87343c630eade Mon Sep 17 00:00:00 2001 From: gamerdonkey Date: Fri, 19 Sep 2025 02:44:20 +0000 Subject: [PATCH] Make creator handle multiple roots and punctuation in recipe names better. --- create_recipe_json.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/create_recipe_json.py b/create_recipe_json.py index dd33af2..872fca0 100644 --- a/create_recipe_json.py +++ b/create_recipe_json.py @@ -1,4 +1,5 @@ import json +import re from anytree import Node, RenderTree from anytree.exporter import DictExporter @@ -64,10 +65,18 @@ prep_time = input("Prep time: ") cook_time = input("Cook time: ") recipe = Recipe(name, description, servings, prep_time, cook_time) -for _, node in nodes.items(): - recipe.add_sub_recipe(node) -filename = f"{name.replace(' ', '_').lower()}.json" +root_keys = nodes.keys() +if len(root_keys) > 1: + print_nodes() + order = input("Multiple tree roots detected, please specify order (comma-separated): ") + root_keys = [int(key.strip()) for key in order.split(",")] + +for key in root_keys: + recipe.add_sub_recipe(nodes[key]) + +filename = re.sub(r"[ -]", "_", name.strip()).lower() +filename = f"{re.sub(r'[^a-z_]', '', filename)}.json" print(f"Writing to {filename}...") with open(filename, 'w') as f: