Compare commits

...

2 Commits

Author SHA1 Message Date
7ce5a2bb8b Updating files. 2025-09-11 05:13:05 +00:00
b0a3901df3 Output full webpage html 2025-09-11 05:11:37 +00:00
3 changed files with 29 additions and 92 deletions

View File

@ -1,6 +1,5 @@
import json import json
from anytree import LevelOrderIter, LevelOrderGroupIter
from anytree.importer import DictImporter from anytree.importer import DictImporter
from sys import argv from sys import argv
@ -56,8 +55,22 @@ recipe_desc = recipe.get("description")
importer = DictImporter() importer = DictImporter()
sub_recipes = [importer.import_(data) for data in recipe["sub_recipes"]] sub_recipes = [importer.import_(data) for data in recipe["sub_recipes"]]
print("<!DOCTYPE html>")
print("<html lang='en'>")
print(f"<head><title>{recipe_name}</title>")
print("<link rel='stylesheet' type='text/css' href='style.css'>")
print("</head>")
print("<body>")
print("<div id='title'>")
print(f"<h1>{recipe_name}</h1>") print(f"<h1>{recipe_name}</h1>")
print("</div>")
print("<div id='description'>")
print(f"<p>{recipe_desc}</p>") print(f"<p>{recipe_desc}</p>")
print("</div>")
print("<div id='needs'>")
print("<h2>Needs</h2>") print("<h2>Needs</h2>")
print("<ul>") print("<ul>")
@ -66,8 +79,10 @@ for sub_recipe in sub_recipes:
print(f" <li>{ingredient.name}</li>") print(f" <li>{ingredient.name}</li>")
print("</ul>") print("</ul>")
print("</div>")
print("<h2>Steps</h2>") print("<div id='preparation'>")
print("<h2>Preparation</h2>")
print("<ol>") print("<ol>")
for sub_recipe in sub_recipes: for sub_recipe in sub_recipes:
@ -76,9 +91,14 @@ for sub_recipe in sub_recipes:
print(f" <li>{task}</li>") print(f" <li>{task}</li>")
print("</ol>") print("</ol>")
print("</div>")
print("<div id='tables'>")
print("<h2>Tabular Layout</h2>")
for sub_recipe in sub_recipes: for sub_recipe in sub_recipes:
print("<table cellspacing='0'>") print("<p>")
print("<table cellspacing='0' border=true>")
output_rows = [] output_rows = []
@ -94,3 +114,9 @@ for sub_recipe in sub_recipes:
print("</tr>") print("</tr>")
print("</table>") print("</table>")
print("</p>")
print("</div>")
print("</body>")
print("</html>")

89
test.py
View File

@ -1,89 +0,0 @@
from anytree import Node
from anytree import RenderTree
from anytree import LevelOrderIter, LevelOrderGroupIter
from anytree.search import find, findall
cut = Node("cut")
cool = Node("cool", parent=cut)
press = Node("press into pan", parent=cool)
stir = Node("stir until coated", parent=press)
cereal = Node("crispy rice cereal (6 cups)", parent=stir)
melt_stir = Node("stir until melted", parent=stir)
marshmellows = Node("marshmellows (10 oz.)", parent=melt_stir)
melt = Node("melt", parent=melt_stir)
butter = Node("butter (3 tbsp)", parent=melt)
output_lines = {}
leaves = [node for node in sorted(cut.leaves, key=lambda node: node.depth, reverse=True)]
max_leaf_name_length = max([len(leaf.name) for leaf in leaves])
for leaf in leaves:
line = f"| {leaf.name.ljust(max_leaf_name_length)} |"
output_lines[leaf] = line
max_depth = max([leaf.depth for leaf in leaves])
for cur_depth in range(max_depth-1, -1, -1):
max_name_length = max([len(node.name) for node in findall(cut, lambda node: node.depth == cur_depth and not node in cut.leaves)])
max_name_length = max(max_name_length, 10)
for leaf in leaves:
task = find(cut, lambda node: node.depth == cur_depth and node in leaf.path)
if task and not task in cut.leaves:
output_lines[leaf] += f" {task.name.center(max_name_length)} |"
else:
output_lines[leaf] += f" {"".ljust(max_name_length)} "
for key in output_lines.keys():
print(output_lines[key])
print("")
output_lines = [""] * len(cut.leaves)
cur_line = 0
last_depth = cut.depth
for node in LevelOrderIter(cut):
if node in cut.leaves:
continue
if last_depth != node.depth:
cur_line = 0
output_lines[cur_line] = f" {node.name} " + output_lines[cur_line]
cur_line += len(node.children) + 1
last_depth = node.depth
for line in output_lines:
print(line)
rows = []
leaves = []
for i in range(len(cut.leaves)):
rows.append([])
leaves.append({"name":"wrong"})
cur_row = 0
for level in LevelOrderGroupIter(cut):
cur_row = 0
for node in reversed(level):
leaf_count = len(node.leaves)
if node in cut.leaves:
leaves[cur_row] = node
else:
rows[cur_row].append(f'<td rowspan="{leaf_count}">{node.name}</td>')
cur_row += max(leaf_count, 1)
last_depth = node.depth
for i, leaf in enumerate(leaves):
rows[i].append(f"<td>{leaf.name}</td>")
rows[i].reverse()
print("<tr>")
for cell in rows[i]:
print(cell)
print("</tr>")