added notes, yields, times and source url to mealie import

This commit is contained in:
vabene1111 2023-03-14 22:46:50 +01:00
parent 008a61823d
commit a3f8b2272c

View File

@ -5,6 +5,7 @@ from zipfile import ZipFile
from cookbook.helper.image_processing import get_filetype
from cookbook.helper.ingredient_parser import IngredientParser
from cookbook.helper.recipe_url_import import parse_servings, parse_servings_text, parse_time
from cookbook.integration.integration import Integration
from cookbook.models import Ingredient, Recipe, Step
@ -23,9 +24,6 @@ class Mealie(Integration):
name=recipe_json['name'].strip(), description=description,
created_by=self.request.user, internal=True, space=self.request.space)
# TODO parse times (given in PT2H3M )
# @vabene check recipe_url_import.iso_duration_to_minutes I think it does what you are looking for
ingredients_added = False
for s in recipe_json['recipe_instructions']:
step = Step.objects.create(
@ -58,6 +56,28 @@ class Mealie(Integration):
pass
recipe.steps.add(step)
if 'notes' in recipe_json and len(recipe_json['notes']) > 0:
notes_text = "#### Notes \n\n"
for n in recipe_json['notes']:
notes_text += f'{n["text"]} \n'
step = Step.objects.create(
instruction=notes_text, space=self.request.space,
)
recipe.steps.add(step)
if 'recipe_yield' in recipe_json:
recipe.servings = parse_servings(recipe_json['recipe_yield'])
recipe.servings_text = parse_servings_text(recipe_json['recipe_yield'])
if 'total_time' in recipe_json and recipe_json['total_time'] is not None:
recipe.working_time = parse_time(recipe_json['total_time'])
if 'org_url' in recipe_json:
recipe.source_url = recipe_json['org_url']
recipe.save()
for f in self.files:
if '.zip' in f['name']:
import_zip = ZipFile(f['file'])