🚧
This commit is contained in:
parent
b2ab88b216
commit
a1ab4c0b5a
34 changed files with 208 additions and 140 deletions
|
@ -1,5 +1,8 @@
|
|||
import json
|
||||
import re
|
||||
import os
|
||||
|
||||
from config import *
|
||||
|
||||
def normalize_ingredients(recipe):
|
||||
if 'recipeIngredient' in recipe:
|
||||
|
@ -42,4 +45,68 @@ def normalize_recipe(recipe):
|
|||
return cleaned_recipe
|
||||
|
||||
|
||||
# TODO
|
||||
# TODO: functions oben sind so nicht mehr funktional
|
||||
|
||||
|
||||
def check_recipe(recipe) -> list:
|
||||
md = []
|
||||
if 'steps' in recipe:
|
||||
steps = recipe['steps']
|
||||
else:
|
||||
steps = []
|
||||
md.append("No steps?")
|
||||
for i, step in enumerate(steps, 1):
|
||||
md += check_ingredients(step)
|
||||
return md
|
||||
|
||||
def normalize_amount(a):
|
||||
if a == round(a):
|
||||
return round(a)
|
||||
else:
|
||||
return a
|
||||
|
||||
def check_ingredients(step):
|
||||
md = []
|
||||
for ingredient in step['ingredients']:
|
||||
i_amount = ingredient["amount"]
|
||||
i_amount = normalize_amount(i_amount)
|
||||
|
||||
if not ingredient.get("unit"):
|
||||
i_unit = ""
|
||||
if i_amount:
|
||||
md.append("- Amount but no unit?")
|
||||
else:
|
||||
i_unit = ingredient["unit"]["name"]
|
||||
|
||||
if i_unit and i_unit not in VALID_UNITS:
|
||||
md.append(f"- Invalid unit {i_unit}")
|
||||
|
||||
if not ingredient.get("food"):
|
||||
md.append("- No food element in ingredient?")
|
||||
continue
|
||||
return md
|
||||
|
||||
|
||||
def make_link(recipe):
|
||||
return f"[{recipe["name"]}]({TANDOOR_URL + "/view/recipe/" + str(recipe["id"])})"
|
||||
|
||||
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)
|
||||
|
||||
for recipe in recipes:
|
||||
md = check_recipe(recipe)
|
||||
if not md:
|
||||
print(f"## 💚 {make_link(recipe)}")
|
||||
else:
|
||||
print(f"## 💔 {make_link(recipe)}")
|
||||
for line in md:
|
||||
print(line)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue