🎨 reformat using black
This commit is contained in:
parent
a1ab4c0b5a
commit
1994109507
5 changed files with 70 additions and 53 deletions
|
@ -4,37 +4,41 @@ import os
|
|||
|
||||
from config import *
|
||||
|
||||
|
||||
def normalize_ingredients(recipe):
|
||||
if 'recipeIngredient' in recipe:
|
||||
recipe['recipeIngredient'] = [
|
||||
ingredient.replace('g / Gramm', 'g') for ingredient in recipe['recipeIngredient']
|
||||
if "recipeIngredient" in recipe:
|
||||
recipe["recipeIngredient"] = [
|
||||
ingredient.replace("g / Gramm", "g")
|
||||
for ingredient in recipe["recipeIngredient"]
|
||||
]
|
||||
recipe['recipeIngredient'] = [
|
||||
ingredient.replace('kg / Kilogramm', 'kg') for ingredient in recipe['recipeIngredient']
|
||||
recipe["recipeIngredient"] = [
|
||||
ingredient.replace("kg / Kilogramm", "kg")
|
||||
for ingredient in recipe["recipeIngredient"]
|
||||
]
|
||||
recipe['recipeIngredient'] = [
|
||||
ingredient.replace('.0 ', ' ') for ingredient in recipe['recipeIngredient']
|
||||
recipe["recipeIngredient"] = [
|
||||
ingredient.replace(".0 ", " ") for ingredient in recipe["recipeIngredient"]
|
||||
]
|
||||
recipe['recipeIngredient'] = [
|
||||
re.sub("^0 (g|kg|Milliliter|None) ", "", ingredient) for ingredient in recipe['recipeIngredient']
|
||||
recipe["recipeIngredient"] = [
|
||||
re.sub("^0 (g|kg|Milliliter|None) ", "", ingredient)
|
||||
for ingredient in recipe["recipeIngredient"]
|
||||
]
|
||||
recipe['recipeIngredient'] = [
|
||||
ingredient \
|
||||
for ingredient in recipe['recipeIngredient'] \
|
||||
if ingredient != "None"
|
||||
recipe["recipeIngredient"] = [
|
||||
ingredient
|
||||
for ingredient in recipe["recipeIngredient"]
|
||||
if ingredient != "None"
|
||||
]
|
||||
return recipe
|
||||
|
||||
|
||||
def normalize_instructions(recipe):
|
||||
if 'recipeInstructions' in recipe:
|
||||
recipe['recipeInstructions'] = [
|
||||
instruction \
|
||||
for instruction in recipe['recipeInstructions'] \
|
||||
if instruction.get('text')
|
||||
if "recipeInstructions" in recipe:
|
||||
recipe["recipeInstructions"] = [
|
||||
instruction
|
||||
for instruction in recipe["recipeInstructions"]
|
||||
if instruction.get("text")
|
||||
]
|
||||
if not recipe['recipeInstructions']:
|
||||
del recipe['recipeInstructions']
|
||||
if not recipe["recipeInstructions"]:
|
||||
del recipe["recipeInstructions"]
|
||||
return recipe
|
||||
|
||||
|
||||
|
@ -50,8 +54,8 @@ def normalize_recipe(recipe):
|
|||
|
||||
def check_recipe(recipe) -> list:
|
||||
md = []
|
||||
if 'steps' in recipe:
|
||||
steps = recipe['steps']
|
||||
if "steps" in recipe:
|
||||
steps = recipe["steps"]
|
||||
else:
|
||||
steps = []
|
||||
md.append("No steps?")
|
||||
|
@ -59,15 +63,17 @@ def check_recipe(recipe) -> list:
|
|||
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']:
|
||||
for ingredient in step["ingredients"]:
|
||||
i_amount = ingredient["amount"]
|
||||
i_amount = normalize_amount(i_amount)
|
||||
|
||||
|
@ -90,11 +96,12 @@ def check_ingredients(step):
|
|||
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:
|
||||
with open(os.path.join(OUTDIR_JSON, json_file), "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
recipes.append(data)
|
||||
|
||||
|
@ -107,6 +114,6 @@ def main():
|
|||
for line in md:
|
||||
print(line)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue