From a3f8b2272c4fe3c5f1513e646a4d901ff54dc2be Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Tue, 14 Mar 2023 22:46:50 +0100 Subject: [PATCH] added notes, yields, times and source url to mealie import --- cookbook/integration/mealie.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/cookbook/integration/mealie.py b/cookbook/integration/mealie.py index 803cc6382..37a0d6fea 100644 --- a/cookbook/integration/mealie.py +++ b/cookbook/integration/mealie.py @@ -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'])