Compare commits
	
		
			2 Commits
		
	
	
		
			d993a70ac7
			...
			ff601bac24
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| ff601bac24 | |||
| 1dcdd10996 | 
							
								
								
									
										31
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					# 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():
 | 
					def print_ingredients():
 | 
				
			||||||
    for i, node in ingredients.items():
 | 
					    for i, node in ingredients.items():
 | 
				
			||||||
        print(f"   {i}.) {node.name}")
 | 
					        print(f"   {i}.) {node.result}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ingredients = {}
 | 
					ingredients = {}
 | 
				
			||||||
@ -17,7 +17,7 @@ while ingredient:
 | 
				
			|||||||
    ingredient = input("Add ingredient: ")
 | 
					    ingredient = input("Add ingredient: ")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ingredient:
 | 
					    if ingredient:
 | 
				
			||||||
        ingredients[i] = Node(ingredient)
 | 
					        ingredients[i] = Node(ingredient, result=ingredient)
 | 
				
			||||||
        i += 1
 | 
					        i += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
task = "start"
 | 
					task = "start"
 | 
				
			||||||
@ -28,8 +28,10 @@ while task:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if task:
 | 
					    if task:
 | 
				
			||||||
        needs = input("List needs (comma-separated): ")
 | 
					        needs = input("List needs (comma-separated): ")
 | 
				
			||||||
 | 
					        description = input("Detailed description: ")
 | 
				
			||||||
 | 
					        result = input("Result of task (e.g. chopped carrots): ")
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        new_task = Node(task)
 | 
					        new_task = Node(task, description=description, result=result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ingredients[i] = new_task
 | 
					        ingredients[i] = new_task
 | 
				
			||||||
        i += 1
 | 
					        i += 1
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ from sys import argv
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def build_rows_depth_first(node, rows, leaf_count=0):
 | 
					def build_rows_depth_first(node, rows, leaf_count=0):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for child in sorted(node.children, key=lambda x: x.size, reverse=True):
 | 
					    for child in sorted(node.children, key=lambda x: x.height, reverse=True):
 | 
				
			||||||
        leaf_count = build_rows_depth_first(child, rows, leaf_count)
 | 
					        leaf_count = build_rows_depth_first(child, rows, leaf_count)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if node.is_leaf:
 | 
					    if node.is_leaf:
 | 
				
			||||||
@ -15,7 +15,7 @@ def build_rows_depth_first(node, rows, leaf_count=0):
 | 
				
			|||||||
    else:
 | 
					    else:
 | 
				
			||||||
        child_leaves = len(node.leaves)
 | 
					        child_leaves = len(node.leaves)
 | 
				
			||||||
        cur_row = leaf_count - child_leaves
 | 
					        cur_row = leaf_count - child_leaves
 | 
				
			||||||
        rows[cur_row].append(f'<td rowspan="{child_leaves}">{node.name}</td>')
 | 
					        rows[cur_row].append(f'<td rowspan="{child_leaves}" title="{node.description}">{node.name}</td>')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return leaf_count
 | 
					    return leaf_count
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user