Compare commits
	
		
			No commits in common. "38a181652aad02619ad0859f49c0d69f024e069b" and "ba6d5f4255eb5a566fca8b1d0829ecc50836b0bd" have entirely different histories.
		
	
	
		
			38a181652a
			...
			ba6d5f4255
		
	
		
							
								
								
									
										46
									
								
								make_tree.py
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								make_tree.py
									
									
									
									
									
								
							@ -8,30 +8,38 @@ def print_ingredients():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ingredients = {}
 | 
					ingredients = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ingredient = "start"
 | 
				
			||||||
i = 0
 | 
					i = 0
 | 
				
			||||||
node = "start"
 | 
					while ingredient:
 | 
				
			||||||
while node:
 | 
					 | 
				
			||||||
    print_ingredients()
 | 
					    print_ingredients()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    node = input("Add node: ")
 | 
					    ingredient = input("Add ingredient: ")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if node:
 | 
					    if ingredient:
 | 
				
			||||||
        needs = input("List needs (comma-separated): ")
 | 
					        ingredients[i] = Node(ingredient, result=ingredient)
 | 
				
			||||||
        description = input("Detailed description: ")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if needs:
 | 
					 | 
				
			||||||
            result = input("Result of node (e.g. chopped carrots): ")
 | 
					 | 
				
			||||||
            new_node = Node(node, description=description, result=result)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            for e in [int(key.strip()) for key in needs.split(",")]:
 | 
					 | 
				
			||||||
                ingredients.pop(e).parent = new_node
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            new_node = Node(node, description=description, result=node)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ingredients[i] = new_node
 | 
					 | 
				
			||||||
        i += 1
 | 
					        i += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for pre, _, node in RenderTree(new_node):
 | 
					task = "start"
 | 
				
			||||||
 | 
					while task:
 | 
				
			||||||
 | 
					    print_ingredients()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    task = input("Add 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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ingredients[i] = new_task
 | 
				
			||||||
 | 
					        i += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for e in [int(key.strip()) for key in needs.split(",")]:
 | 
				
			||||||
 | 
					            ingredients.pop(e).parent = new_task
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for pre, _, node in RenderTree(new_task):
 | 
				
			||||||
    print(f"{pre}{node.name}")
 | 
					    print(f"{pre}{node.name}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
name = input("Recipe name: ")
 | 
					name = input("Recipe name: ")
 | 
				
			||||||
@ -40,5 +48,5 @@ if name:
 | 
				
			|||||||
    name = name.replace(" ", "_")
 | 
					    name = name.replace(" ", "_")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    with open(f"{name}.json", 'w') as f:
 | 
					    with open(f"{name}.json", 'w') as f:
 | 
				
			||||||
        JsonExporter(indent=2).write(new_node, f)
 | 
					        JsonExporter(indent=2).write(new_task, f)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,4 @@
 | 
				
			|||||||
from anytree import LevelOrderIter, LevelOrderGroupIter
 | 
					from anytree import LevelOrderGroupIter
 | 
				
			||||||
from anytree.importer import JsonImporter
 | 
					from anytree.importer import JsonImporter
 | 
				
			||||||
from sys import argv
 | 
					from sys import argv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -20,7 +20,7 @@ def build_rows_depth_first(node, rows, leaf_count=0):
 | 
				
			|||||||
        rows[cur_row].append(f'<th>{node.name}</th>')
 | 
					        rows[cur_row].append(f'<th>{node.name}</th>')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if colspan > 1:
 | 
					        if colspan > 1:
 | 
				
			||||||
            rows[cur_row].append(f'<td colspan="{colspan-1}" class="filler"></td>')
 | 
					            rows[cur_row].append(f'<td colspan="{colspan-1}"></td>')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        leaf_count += 1
 | 
					        leaf_count += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -46,23 +46,6 @@ for i in range(len(root.leaves)):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
build_rows_depth_first(root, output_rows)
 | 
					build_rows_depth_first(root, output_rows)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print("<h2>Ingredients</h2>")
 | 
					 | 
				
			||||||
print("<ul>")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
for ingredient in root.leaves:
 | 
					 | 
				
			||||||
    print(f" <li>{ingredient.name}</li>")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("</ul>")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("<h2>Steps</h2>")
 | 
					 | 
				
			||||||
print("<ol>")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
tasks = [node for node in LevelOrderIter(root) if not node.is_leaf]
 | 
					 | 
				
			||||||
for task in reversed(tasks):
 | 
					 | 
				
			||||||
    print(f"<li>{task.description}</li>")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("</ol>")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("<table cellspacing='0'>")
 | 
					print("<table cellspacing='0'>")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for row in output_rows:
 | 
					for row in output_rows:
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user