🧹 normalize instructions
This commit is contained in:
parent
2ac5eebe61
commit
6e2c83eaa3
12 changed files with 27 additions and 66 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Reference in a new issue