🚧 initial commit
This commit is contained in:
commit
729b1dde32
5 changed files with 1502 additions and 0 deletions
31
1_clean_json.py
Normal file
31
1_clean_json.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import json
|
||||
|
||||
input_file = 'export_2025-06-01.json'
|
||||
output_file = 'export_2025-06-01_clean.json'
|
||||
|
||||
with open(input_file, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
|
||||
def normalize_ingredients(recipe):
|
||||
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('.0 ', ' ') for ingredient in recipe['recipeIngredient']
|
||||
]
|
||||
return recipe
|
||||
|
||||
if isinstance(data, list):
|
||||
cleaned_data = [normalize_ingredients(recipe) for recipe in data]
|
||||
else:
|
||||
cleaned_data = normalize_ingredients(data)
|
||||
|
||||
# Write the cleaned JSON data to a new file
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(cleaned_data, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f"Cleaned data written to '{output_file}'")
|
Loading…
Add table
Add a link
Reference in a new issue