From 52d8e8d9ba43e6b53ceea291c04a14ad79bdd536 Mon Sep 17 00:00:00 2001 From: ellezhu1 Date: Sun, 21 Apr 2024 06:09:55 +0000 Subject: [PATCH 1/6] issue2982 - plantToEat --- .gitignore | 18 ++++++++++++++++++ cookbook/integration/plantoeat.py | 31 +++++++++++++++++++------------ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 143271c6c..f4aba1c5b 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,21 @@ cookbook/templates/sw.js vue/.yarn vue3/.vite vue3/node_modules +cookbook/integration/plantoeat_test.txt +cookbook/integration/crouton-sampl.zip +cookbook/integration/crouton-sampl/Chocolate Caramel Tart.crumb +cookbook/integration/crouton-sampl/Japanese Strawberry Shortcake.crumb +cookbook/integration/crouton-sampl/Mango Pudding.crumb +cookbook/integration/crouton-sampl/Matcha Lava Cake.crumb +cookbook/integration/crouton-sampl/Peppermint Hot Chocolate Recipe.crumb +cookbook/integration/crouton-sampl/Purin (Japanese Creme Caramel).crumb +cookbook/integration/crouton-sampl/Strawberry Bingsu Recipe.crumb +cookbook/integration/crouton-sampl/Ube Basque Cheesecake.crumb +cookbook/integration/crouton-sampl/__MACOSX/._Chocolate Caramel Tart.crumb +cookbook/integration/crouton-sampl/__MACOSX/._Japanese Strawberry Shortcake.crumb +cookbook/integration/crouton-sampl/__MACOSX/._Mango Pudding.crumb +cookbook/integration/crouton-sampl/__MACOSX/._Matcha Lava Cake.crumb +cookbook/integration/crouton-sampl/__MACOSX/._Peppermint Hot Chocolate Recipe.crumb +cookbook/integration/crouton-sampl/__MACOSX/._Purin (Japanese Creme Caramel).crumb +cookbook/integration/crouton-sampl/__MACOSX/._Strawberry Bingsu Recipe.crumb +cookbook/integration/crouton-sampl/__MACOSX/._Ube Basque Cheesecake.crumb diff --git a/cookbook/integration/plantoeat.py b/cookbook/integration/plantoeat.py index c4cc0f135..b69b63283 100644 --- a/cookbook/integration/plantoeat.py +++ b/cookbook/integration/plantoeat.py @@ -4,6 +4,7 @@ import requests import validators 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 @@ -18,32 +19,38 @@ class Plantoeat(Integration): tags = None ingredients = [] directions = [] - description = '' + fields = {} for line in file.replace('\r', '').split('\n'): if line.strip() != '': if 'Title:' in line: - title = line.replace('Title:', '').replace('"', '').strip() + fields['name'] = line.replace('Title:', '').replace('"', '').strip() if 'Description:' in line: - description = line.replace('Description:', '').strip() - if 'Source:' in line or 'Serves:' in line or 'Prep Time:' in line or 'Cook Time:' in line: - directions.append(line.strip() + '\n') + fields['description'] = line.replace('Description:', '').strip() + if 'Serves:' in line: + fields['servings'] = parse_servings(line.replace('Serves:', '').strip()) + if 'Source:' in line: + fields['source_url'] = line.replace('Source:', '').strip() if 'Photo Url:' in line: image_url = line.replace('Photo Url:', '').strip() + if 'Prep Time:' in line: + fields['working_time'] = parse_time(line.replace('Prep Time:', '').strip()) + if 'Cook Time:' in line: + fields['waiting_time'] = parse_time(line.replace('Cook Time:', '').strip()) if 'Tags:' in line: tags = line.replace('Tags:', '').strip() - if ingredient_mode: - if len(line) > 2 and 'Instructions:' not in line: - ingredients.append(line.strip()) - if direction_mode: - if len(line) > 2: - directions.append(line.strip() + '\n') if 'Ingredients:' in line: ingredient_mode = True if 'Directions:' in line: ingredient_mode = False direction_mode = True + if ingredient_mode: + if len(line) > 2 and 'Ingredients:' not in line: + ingredients.append(line.strip()) + if direction_mode: + if len(line) > 2: + directions.append(line.strip() + '\n') - recipe = Recipe.objects.create(name=title, description=description, created_by=self.request.user, internal=True, space=self.request.space) + recipe = Recipe.objects.create(**fields, created_by=self.request.user, internal=True, space=self.request.space) step = Step.objects.create( instruction='\n'.join(directions) + '\n\n', space=self.request.space, show_ingredients_table=self.request.user.userpreference.show_step_ingredients, From 7ea95923984d1e2f15a5e520ea60d5902e056e81 Mon Sep 17 00:00:00 2001 From: ellezhu1 Date: Sun, 21 Apr 2024 06:25:02 +0000 Subject: [PATCH 2/6] tested --- .gitignore | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/.gitignore b/.gitignore index f4aba1c5b..143271c6c 100644 --- a/.gitignore +++ b/.gitignore @@ -88,21 +88,3 @@ cookbook/templates/sw.js vue/.yarn vue3/.vite vue3/node_modules -cookbook/integration/plantoeat_test.txt -cookbook/integration/crouton-sampl.zip -cookbook/integration/crouton-sampl/Chocolate Caramel Tart.crumb -cookbook/integration/crouton-sampl/Japanese Strawberry Shortcake.crumb -cookbook/integration/crouton-sampl/Mango Pudding.crumb -cookbook/integration/crouton-sampl/Matcha Lava Cake.crumb -cookbook/integration/crouton-sampl/Peppermint Hot Chocolate Recipe.crumb -cookbook/integration/crouton-sampl/Purin (Japanese Creme Caramel).crumb -cookbook/integration/crouton-sampl/Strawberry Bingsu Recipe.crumb -cookbook/integration/crouton-sampl/Ube Basque Cheesecake.crumb -cookbook/integration/crouton-sampl/__MACOSX/._Chocolate Caramel Tart.crumb -cookbook/integration/crouton-sampl/__MACOSX/._Japanese Strawberry Shortcake.crumb -cookbook/integration/crouton-sampl/__MACOSX/._Mango Pudding.crumb -cookbook/integration/crouton-sampl/__MACOSX/._Matcha Lava Cake.crumb -cookbook/integration/crouton-sampl/__MACOSX/._Peppermint Hot Chocolate Recipe.crumb -cookbook/integration/crouton-sampl/__MACOSX/._Purin (Japanese Creme Caramel).crumb -cookbook/integration/crouton-sampl/__MACOSX/._Strawberry Bingsu Recipe.crumb -cookbook/integration/crouton-sampl/__MACOSX/._Ube Basque Cheesecake.crumb From 68e6ab4be5f7992de6438a6f0693228e23e20cb7 Mon Sep 17 00:00:00 2001 From: ellezhu1 Date: Sun, 21 Apr 2024 08:31:29 +0000 Subject: [PATCH 3/6] get step name --- cookbook/integration/nextcloud_cookbook.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cookbook/integration/nextcloud_cookbook.py b/cookbook/integration/nextcloud_cookbook.py index 4357c509b..303e40855 100644 --- a/cookbook/integration/nextcloud_cookbook.py +++ b/cookbook/integration/nextcloud_cookbook.py @@ -60,6 +60,11 @@ class NextcloudCookbook(Integration): step = Step.objects.create( instruction=s, space=self.request.space, show_ingredients_table=self.request.user.userpreference.show_step_ingredients, ) + step.name = re.search(r'(\w+):\\n', s) + + + + if not ingredients_added: if len(recipe_json['description'].strip()) > 500: step.instruction = recipe_json['description'].strip() + '\n\n' + step.instruction From d81e7f6c2b8bf5694ba75bb5b5b1023df4c7cc1d Mon Sep 17 00:00:00 2001 From: ellezhu1 Date: Sun, 21 Apr 2024 11:28:51 +0000 Subject: [PATCH 4/6] remove ##ingredients --- cookbook/integration/nextcloud_cookbook.py | 26 ++++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/cookbook/integration/nextcloud_cookbook.py b/cookbook/integration/nextcloud_cookbook.py index 303e40855..c065ed7c3 100644 --- a/cookbook/integration/nextcloud_cookbook.py +++ b/cookbook/integration/nextcloud_cookbook.py @@ -60,25 +60,17 @@ class NextcloudCookbook(Integration): step = Step.objects.create( instruction=s, space=self.request.space, show_ingredients_table=self.request.user.userpreference.show_step_ingredients, ) - step.name = re.search(r'(\w+):\\n', s) - - - - if not ingredients_added: - if len(recipe_json['description'].strip()) > 500: - step.instruction = recipe_json['description'].strip() + '\n\n' + step.instruction - - ingredients_added = True - - ingredient_parser = IngredientParser(self.request, True) + ingredient_parser = IngredientParser(self.request, True) + if ingredients_added == False: for ingredient in recipe_json['recipeIngredient']: - 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, - )) + ingredients_added = True + if ingredient.find('##') == -1: + 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 'nutrition' in recipe_json: From 4933726b79395c415fd7c71af5bcc7bd4d24eb1b Mon Sep 17 00:00:00 2001 From: ellezhu1 Date: Sun, 21 Apr 2024 21:23:40 +0000 Subject: [PATCH 5/6] made some changes --- cookbook/integration/nextcloud_cookbook.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cookbook/integration/nextcloud_cookbook.py b/cookbook/integration/nextcloud_cookbook.py index c065ed7c3..1520e9014 100644 --- a/cookbook/integration/nextcloud_cookbook.py +++ b/cookbook/integration/nextcloud_cookbook.py @@ -65,7 +65,10 @@ class NextcloudCookbook(Integration): if ingredients_added == False: for ingredient in recipe_json['recipeIngredient']: ingredients_added = True - if ingredient.find('##') == -1: + if ingredient.startswith('##'): + subheader = ingredient.replace('##', '', 1) + step.ingredients.add(Ingredient.objects.create(note=subheader, is_header=True, no_amount=True, space=self.request.space)) + else: amount, unit, food, note = ingredient_parser.parse(ingredient) f = ingredient_parser.get_food(food) u = ingredient_parser.get_unit(unit) From 771375b40b39e3aac6217548e52842c44bcabee2 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sat, 27 Apr 2024 09:28:19 +0200 Subject: [PATCH 6/6] added missing doctype attribute --- cookbook/templates/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index 5a7e1650a..ca310f0af 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -4,7 +4,7 @@ {% load custom_tags %} {% theme_values request as theme_values %} - + {% block title %}