✨ lib: read_recipes()
This commit is contained in:
parent
46d4963188
commit
ec3e052ddb
1 changed files with 21 additions and 0 deletions
21
lib.py
Normal file
21
lib.py
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue