Make creator handle multiple roots and punctuation in recipe names better.
This commit is contained in:
parent
a3e8e89160
commit
6c18cb8dbe
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
from anytree import Node, RenderTree
|
from anytree import Node, RenderTree
|
||||||
from anytree.exporter import DictExporter
|
from anytree.exporter import DictExporter
|
||||||
@ -64,10 +65,18 @@ prep_time = input("Prep time: ")
|
|||||||
cook_time = input("Cook time: ")
|
cook_time = input("Cook time: ")
|
||||||
|
|
||||||
recipe = Recipe(name, description, servings, prep_time, 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}...")
|
print(f"Writing to {filename}...")
|
||||||
with open(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user