From 6c7ad52c72bc5795d43a8965d8d5e718166f749e Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 12 Apr 2026 23:51:21 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20lib:=20read=5Frecipes()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_clean_json.py | 8 ++------ 2_to_markdown.py | 7 ++----- fruehstueck.py | 14 +------------- report_allergene.py | 8 ++------ 4 files changed, 7 insertions(+), 30 deletions(-) diff --git a/1_clean_json.py b/1_clean_json.py index 52d4ff3..2847464 100644 --- a/1_clean_json.py +++ b/1_clean_json.py @@ -3,6 +3,7 @@ import re import os from config import * +from lib import * def clean_recipe(recipe): @@ -85,12 +86,7 @@ def main(): # Read all and check - recipes = [] - for json_file in os.listdir(OUTDIR_JSON): - with open(os.path.join(OUTDIR_JSON, json_file), "r", encoding="utf-8") as f: - data = json.load(f) - recipes.append(data) - + recipes = read_recipes() for recipe in recipes: md = check_recipe(recipe) if not md: diff --git a/2_to_markdown.py b/2_to_markdown.py index 594de27..3f50b15 100644 --- a/2_to_markdown.py +++ b/2_to_markdown.py @@ -8,6 +8,7 @@ import os from tqdm import tqdm from config import * +from lib import * include_title = False @@ -107,11 +108,7 @@ def format_recipe_to_markdown(recipe): def main(): - recipes = [] - for json_file in os.listdir(OUTDIR_JSON): - with open(os.path.join(OUTDIR_JSON, json_file), "r", encoding="utf-8") as f: - data = json.load(f) - recipes.append(data) + recipes = read_recipes() for recipe in tqdm(recipes): markdown_fn = f"{recipe.get('name', 'Untitled Recipe')}.md" diff --git a/fruehstueck.py b/fruehstueck.py index a28673a..b4863e4 100644 --- a/fruehstueck.py +++ b/fruehstueck.py @@ -77,19 +77,7 @@ def main(): Path("fruehstueck.csv").unlink(missing_ok=True) - recipes = [] - for json_file in os.listdir(OUTDIR_JSON): - with open(os.path.join(OUTDIR_JSON, json_file), "r", encoding="utf-8") as f: - data = json.load(f) - recipes.append(data) - recipes.sort(key=lambda r: r["name"]) - - # filter "Frühstück" - recipes = [ - r - for r in recipes - if any(k["name"] == "Fr\u00fchst\u00fcck" for k in r["keywords"]) - ] + recipes = read_recipes(keyword="Frühstück") with open("fruehstueck.csv", "w", newline="") as f: fwriter = csv.writer( diff --git a/report_allergene.py b/report_allergene.py index 2e56cff..5e0e179 100644 --- a/report_allergene.py +++ b/report_allergene.py @@ -7,6 +7,7 @@ import os from tqdm import tqdm from config import * +from lib import * def allergens_for_step_ingredients(step): @@ -59,12 +60,7 @@ def main(): Path("report_allergene_korrektur.csv").unlink(missing_ok=True) Path("report_allergene.md").unlink(missing_ok=True) - recipes = [] - for json_file in os.listdir(OUTDIR_JSON): - with open(os.path.join(OUTDIR_JSON, json_file), "r", encoding="utf-8") as f: - data = json.load(f) - recipes.append(data) - recipes.sort(key=lambda r: r["name"]) + recipes = read_recipes() for recipe in recipes: with open("report_allergene_korrektur.csv", "a") as f: