import csv import json import os import pprint import re import sys from collections import defaultdict from datetime import timedelta from pathlib import Path from tqdm import tqdm from config import * from lib import read_recipes # TODO read from csv wanted_servings = { "Aufstrich Zwiebel & Kümmel": 100, "Cashew-Streichkäse": 100, "GPN-Tomatenbutter": 100, "Granatapfelcreme": 100, "Gulaschmarmelade": 100, "Hummus": 100, "Matelade Apfel": 100, "Mungobohnenhummus mit Jalapenos und Zatar": 100, "Rauchige Schwarze Bohnencreme": 100, } # XXX move to lib def grams(ingredient): conversion = None for c in ingredient["conversions"]: if c["unit"] in ["g / Gramm", "g"]: conversion = c if conversion: return conversion.get("amount") def main(): recipes = read_recipes(keyword="Frühstück") inventory = {} for recipe in recipes: scale_factor = wanted_servings[recipe["name"]] / recipe["servings"] r_name = recipe["name"] for step in recipe["steps"]: for ingredient in step["ingredients"]: if not ingredient.get("food"): raise ValueError("No food in ingredient") continue i_grams = scale_factor * (grams(ingredient) or 0) i_name = ingredient["food"]["name"] i_description = ingredient["food"][ "description" ] # XXX probably not what i wanted inventory.setdefault(i_name, []).append((i_grams, r_name)) print("!!! alert") print("automatisch erstellt, nicht editieren...") print("!!!") for ingredient, entries in inventory.items(): total = sum(amount for amount, _ in entries) print(f"## {ingredient}") print(f"- **{total:.1f}g** **Total**") for i_grams, r_name in entries: print(f"- {i_grams:.1f}g {r_name}") if __name__ == "__main__": main()