🧹 normalize instructions

This commit is contained in:
neingeist 2025-06-02 12:32:45 +02:00
parent 2ac5eebe61
commit 6e2c83eaa3
12 changed files with 27 additions and 66 deletions

View file

@ -29,10 +29,30 @@ def normalize_ingredients(recipe):
]
return recipe
def normalize_instructions(recipe):
if 'recipeInstructions' in recipe:
recipe['recipeInstructions'] = [
instruction \
for instruction in recipe['recipeInstructions'] \
if instruction.get('text')
]
if not recipe['recipeInstructions']:
del recipe['recipeInstructions']
return recipe
def normalize_recipe(recipe):
cleaned_recipe = recipe
cleaned_recipe = normalize_ingredients(cleaned_recipe)
cleaned_recipe = normalize_instructions(cleaned_recipe)
return cleaned_recipe
if isinstance(data, list):
cleaned_data = [normalize_ingredients(recipe) for recipe in data]
cleaned_data = [normalize_recipe(recipe) for recipe in data]
else:
cleaned_data = normalize_ingredients(data)
cleaned_data = normalize_recipe(data)
# Write the cleaned JSON data to a new file
with open(output_file, 'w', encoding='utf-8') as f: