From ec3e052ddbdb5b546fe8653c3ac3d9cb1dd4d52f Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 12 Apr 2026 23:52:30 +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 --- lib.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib.py diff --git a/lib.py b/lib.py new file mode 100644 index 0000000..64d1bab --- /dev/null +++ b/lib.py @@ -0,0 +1,21 @@ +import os +import json + +from config import * + + +def read_recipes(keyword=None): + 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 on keyword + if keyword: + recipes = [ + r for r in recipes if any(k["name"] == keyword for k in r["keywords"]) + ] + + return recipes