From eb8422cb5162a1f02dd94384c2da4fcf0755afee Mon Sep 17 00:00:00 2001 From: blowk <2361395+blowk@users.noreply.github.com> Date: Sun, 22 Oct 2023 20:09:27 +0200 Subject: [PATCH 1/2] Import tags on mealie recipes --- cookbook/integration/mealie.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cookbook/integration/mealie.py b/cookbook/integration/mealie.py index 5e4e1578d..2d46e2cde 100644 --- a/cookbook/integration/mealie.py +++ b/cookbook/integration/mealie.py @@ -7,7 +7,7 @@ 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 +from cookbook.models import Ingredient, Keyword, Recipe, Step class Mealie(Integration): @@ -56,6 +56,11 @@ class Mealie(Integration): except Exception: pass + if 'tags' in recipe_json and len(recipe_json['tags']) > 0: + for k in recipe_json['tags']: + keyword, created = Keyword.objects.get_or_create(name=k["name"].strip(), space=self.request.space) + recipe.keywords.add(keyword) + if 'notes' in recipe_json and len(recipe_json['notes']) > 0: notes_text = "#### Notes \n\n" for n in recipe_json['notes']: From 4cb94a17592b8859e47dda251230501c7829133c Mon Sep 17 00:00:00 2001 From: blowk <2361395+blowk@users.noreply.github.com> Date: Fri, 17 Nov 2023 19:34:36 +0100 Subject: [PATCH 2/2] Update chowdown.py --- cookbook/integration/chowdown.py | 42 +++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/cookbook/integration/chowdown.py b/cookbook/integration/chowdown.py index 3d41cf481..bcd450fa5 100644 --- a/cookbook/integration/chowdown.py +++ b/cookbook/integration/chowdown.py @@ -4,6 +4,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, Keyword, Recipe, Step @@ -26,6 +27,12 @@ class Chowdown(Integration): line = fl.decode("utf-8") if 'title:' in line: title = line.replace('title:', '').replace('"', '').strip() + if 'description:' in line: + description = line.replace('description:', '').replace('"', '').strip() + if 'prep_time:' in line: + prep_time = line.replace('prep_time:', '').replace('"', '').strip() + if 'yield:' in line: + serving = line.replace('yield:', '').replace('"', '').strip() if 'image:' in line: image = line.replace('image:', '').strip() if 'tags:' in line: @@ -47,16 +54,43 @@ class Chowdown(Integration): if description_mode and len(line) > 3 and '---' not in line: descriptions.append(line) - recipe = Recipe.objects.create(name=title, created_by=self.request.user, internal=True, space=self.request.space) + recipe = Recipe.objects.create(name=title, description=description, created_by=self.request.user, internal=True, space=self.request.space) for k in tags.split(','): print(f'adding keyword {k.strip()}') keyword, created = Keyword.objects.get_or_create(name=k.strip(), space=self.request.space) recipe.keywords.add(keyword) - step = Step.objects.create( - instruction='\n'.join(directions) + '\n\n' + '\n'.join(descriptions), space=self.request.space, show_ingredients_table=self.request.user.userpreference.show_step_ingredients, - ) + ingredients_added = False + for direction in directions: + if len(direction.strip()) > 0: + step = Step.objects.create( + instruction=direction, name='', space=self.request.space, show_ingredients_table=self.request.user.userpreference.show_step_ingredients, + ) + else: + step = Step.objects.create( + instruction=direction, space=self.request.space, show_ingredients_table=self.request.user.userpreference.show_step_ingredients, + ) + if not ingredients_added: + ingredients_added = True + + ingredient_parser = IngredientParser(self.request, True) + for ingredient in ingredients: + if len(ingredient.strip()) > 0: + amount, unit, food, note = ingredient_parser.parse(ingredient) + f = ingredient_parser.get_food(food) + u = ingredient_parser.get_unit(unit) + step.ingredients.add(Ingredient.objects.create( + food=f, unit=u, amount=amount, note=note, original_text=ingredient, space=self.request.space, + )) + recipe.steps.add(step) + + if 'recipe_yield': + recipe.servings = parse_servings(serving) + recipe.servings_text = 'servings' + + if 'total_time' and prep_time is not None: + recipe.working_time = parse_time(prep_time) ingredient_parser = IngredientParser(self.request, True) for ingredient in ingredients: