Compare commits

..

2 Commits

2 changed files with 16 additions and 7 deletions

View File

@ -6,8 +6,8 @@ HTML.
I used these scripts to create my [recipes I used these scripts to create my [recipes
site](https://tilde.town/~gamerdonkey/recipes/) here on town. Fun fact: you can site](https://tilde.town/~gamerdonkey/recipes/) here on town. Fun fact: you can
replace the `html` with `json` in the URLs to get my recipes in their raw JSON replace the `html` in the URLs with `json` to get my recipes in their raw JSON
format. format!
## Requirements ## Requirements
@ -54,8 +54,8 @@ JSON YOU DID NOT CREATE YOURSELF!**
This script takes an argument pointing to a directory of recipe JSON files, in This script takes an argument pointing to a directory of recipe JSON files, in
the format created by the `create_recipe_json.py` script. It then does a the format created by the `create_recipe_json.py` script. It then does a
recursive depth-first search on each tree in that file to generate an HTML recursive depth-first search on each tree in each file to generate HTML files
file with a traditional recipe and a tabular-style recipe card. It also takes with a traditional recipe and a tabular-style recipe card. You may also pass
an optional argument pointing to a file and, if given, the contents of that an optional argument pointing to a file and, if given, the contents of that
file will be inserted into the header section of the generated `index.html`. file will be inserted into the header section of the generated `index.html`.

View File

@ -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: