Compare commits
No commits in common. "ff601bac2498a4a3e21e82a506e57af3c9ca86dc" and "d993a70ac7658b9554c0253d9c5753c8e6e3ef3e" have entirely different histories.
ff601bac24
...
d993a70ac7
31
README.md
31
README.md
@ -1,31 +0,0 @@
|
||||
# Recipes for Engineers
|
||||
|
||||
Store recipes in a nerdy JSON tree format and use that to generate [Cooking for Engineers]()-style tabular recipe cards in HTML.
|
||||
|
||||
Right now this project is just a set of scripts.
|
||||
|
||||
## `make_tree.py`
|
||||
|
||||
This is a fairly naive script that walks you through the process of turning a recipe into a tree structure. It has you list out ingredients, and then add tasks to perform on those ingredients. You end up with a tree that is something like this:
|
||||
|
||||
```
|
||||
shake and grill for 20 more mins
|
||||
+-- grill for 20 mins
|
||||
+-- wrap in foil
|
||||
+-- season to taste
|
||||
|-- salt and pepper
|
||||
|-- dice
|
||||
| |-- rosemary
|
||||
| |-- thyme
|
||||
| +-- basil
|
||||
+-- lightly coat
|
||||
|-- olive oil
|
||||
+-- chop into quarters
|
||||
+-- red potatoes
|
||||
```
|
||||
|
||||
Leaves are raw ingredients, other nodes are tasks. The tree is output to a JSON file.
|
||||
|
||||
## `output_html.py`
|
||||
|
||||
This script takes that JSON file and does a recursive depth-first search to render an HTML-table-based recipe card.
|
@ -4,7 +4,7 @@ from anytree.exporter import JsonExporter
|
||||
|
||||
def print_ingredients():
|
||||
for i, node in ingredients.items():
|
||||
print(f" {i}.) {node.result}")
|
||||
print(f" {i}.) {node.name}")
|
||||
|
||||
|
||||
ingredients = {}
|
||||
@ -17,7 +17,7 @@ while ingredient:
|
||||
ingredient = input("Add ingredient: ")
|
||||
|
||||
if ingredient:
|
||||
ingredients[i] = Node(ingredient, result=ingredient)
|
||||
ingredients[i] = Node(ingredient)
|
||||
i += 1
|
||||
|
||||
task = "start"
|
||||
@ -28,10 +28,8 @@ while task:
|
||||
|
||||
if task:
|
||||
needs = input("List needs (comma-separated): ")
|
||||
description = input("Detailed description: ")
|
||||
result = input("Result of task (e.g. chopped carrots): ")
|
||||
|
||||
new_task = Node(task, description=description, result=result)
|
||||
new_task = Node(task)
|
||||
|
||||
ingredients[i] = new_task
|
||||
i += 1
|
||||
|
@ -5,7 +5,7 @@ from sys import argv
|
||||
|
||||
def build_rows_depth_first(node, rows, leaf_count=0):
|
||||
|
||||
for child in sorted(node.children, key=lambda x: x.height, reverse=True):
|
||||
for child in sorted(node.children, key=lambda x: x.size, reverse=True):
|
||||
leaf_count = build_rows_depth_first(child, rows, leaf_count)
|
||||
|
||||
if node.is_leaf:
|
||||
@ -15,7 +15,7 @@ def build_rows_depth_first(node, rows, leaf_count=0):
|
||||
else:
|
||||
child_leaves = len(node.leaves)
|
||||
cur_row = leaf_count - child_leaves
|
||||
rows[cur_row].append(f'<td rowspan="{child_leaves}" title="{node.description}">{node.name}</td>')
|
||||
rows[cur_row].append(f'<td rowspan="{child_leaves}">{node.name}</td>')
|
||||
|
||||
return leaf_count
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user