from os import path, walk from recipe import Recipe from sys import argv if len(argv) < 2: print(f"Usage: {argv[0]} ") exit(1) recipe_dir = argv[1] recipe_names = {} for dirpath, dirnames, filenames in walk(recipe_dir): for filename in filenames: if filename.endswith("json"): recipe = Recipe(path.join(dirpath, filename)) html = recipe.to_html() html_filepath = path.join(dirpath, f"{filename.rsplit('.', maxsplit=1)[0]}.html") with open(html_filepath, 'w') as html_file: html_file.write(html) recipe_names[recipe.name] = path.relpath(html_filepath, start=recipe_dir) index_html = f""" Recipes

Recipes

These are recipes that I'd like to share.

""" with open(path.join(recipe_dir, "index.html"), 'w') as index_file: index_file.write(index_html)