From c88566a4aef714f8b7e6dc227bce08834eeca902 Mon Sep 17 00:00:00 2001 From: tomtjes <7606307+tomtjes@users.noreply.github.com> Date: Fri, 22 Jul 2022 12:14:23 -0400 Subject: [PATCH] fix minor issues in CopyMeThat importer improve handling of empty fields and fields that exceed character limits --- cookbook/integration/copymethat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cookbook/integration/copymethat.py b/cookbook/integration/copymethat.py index a581ab73d..421c967d7 100644 --- a/cookbook/integration/copymethat.py +++ b/cookbook/integration/copymethat.py @@ -24,7 +24,7 @@ class CopyMeThat(Integration): try: source = file.find("a", {"id": "original_link"}).text except AttributeError: - source = '' + source = None recipe = Recipe.objects.create(name=file.find("div", {"id": "name"}).text.strip()[:128], source_url=source, created_by=self.request.user, internal=True, space=self.request.space, ) @@ -58,10 +58,10 @@ class CopyMeThat(Integration): ingredients = file.find("ul", {"id": "recipeIngredients"}) if isinstance(ingredients, Tag): for ingredient in ingredients.children: - if not isinstance(ingredient, Tag) or ingredient.text == "": + if not isinstance(ingredient, Tag) or not ingredient.text.strip() or "recipeIngredient_spacer" in ingredient['class']: continue if any(x in ingredient['class'] for x in ["recipeIngredient_subheader", "recipeIngredient_note"]): - step.ingredients.add(Ingredient.objects.create(is_header=True, note=ingredient.text.strip(), original_text=ingredient.text.strip(), space=self.request.space, )) + step.ingredients.add(Ingredient.objects.create(is_header=True, note=ingredient.text.strip()[:256], original_text=ingredient.text.strip(), space=self.request.space, )) else: amount, unit, food, note = ingredient_parser.parse(ingredient.text.strip()) f = ingredient_parser.get_food(food)