From 984d5aae118078c87adee44cc09f1fb255015792 Mon Sep 17 00:00:00 2001 From: smilerz Date: Sun, 2 May 2021 20:06:53 -0500 Subject: [PATCH] misc cleanup --- cookbook/helper/recipe_url_import.py | 5 ++--- cookbook/helper/scrapers/scrapers.py | 6 +++--- cookbook/templates/url_import.html | 1 + cookbook/views/api.py | 1 - cookbook/views/data.py | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cookbook/helper/recipe_url_import.py b/cookbook/helper/recipe_url_import.py index 55aa38bb6..7a4de1910 100644 --- a/cookbook/helper/recipe_url_import.py +++ b/cookbook/helper/recipe_url_import.py @@ -14,11 +14,10 @@ from recipe_scrapers._utils import get_minutes def get_from_scraper(scrape, space): # converting the scrape_me object to the existing json format based on ld+json - recipe_json = {} try: recipe_json['name'] = parse_name(scrape.title() or None) - except (TypeError, AttributeError, ElementNotFoundInHtml, NotImplementedError): + except Exception: recipe_json['name'] = None if not recipe_json['name']: try: @@ -28,7 +27,7 @@ def get_from_scraper(scrape, space): try: description = scrape.schema.data.get("description") or '' - except (AttributeError, ElementNotFoundInHtml, NotImplementedError, SchemaOrgException): + except Exception: description = '' recipe_json['description'] = parse_description(description) diff --git a/cookbook/helper/scrapers/scrapers.py b/cookbook/helper/scrapers/scrapers.py index 8b0ae78b8..ff052f2c1 100644 --- a/cookbook/helper/scrapers/scrapers.py +++ b/cookbook/helper/scrapers/scrapers.py @@ -25,9 +25,9 @@ def text_scraper(text, url=None): class TextScraper(scraper_class): def __init__( - self, - page_data, - url=None + self, + page_data, + url=None ): self.wild_mode = False # self.exception_handling = None # TODO add new method here, old one was deprecated diff --git a/cookbook/templates/url_import.html b/cookbook/templates/url_import.html index d70104c0a..ef62b3b5d 100644 --- a/cookbook/templates/url_import.html +++ b/cookbook/templates/url_import.html @@ -722,6 +722,7 @@ msg += err.bodyText } else { msg += ' ' + err.status + ' ' + err.statusText + this.preview = true } this.makeToast(gettext('Error'), msg, 'danger') }) diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 248f81169..429def37d 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -680,7 +680,6 @@ def recipe_from_source(request): 'images': images, }) - else: return JsonResponse( { diff --git a/cookbook/views/data.py b/cookbook/views/data.py index 3b657331f..edf041dfc 100644 --- a/cookbook/views/data.py +++ b/cookbook/views/data.py @@ -163,7 +163,7 @@ def import_url(request): elif isinstance(ing['amount'], float) \ or isinstance(ing['amount'], int): ingredient.amount = ing['amount'] - ingredient.note = ing['note'] if 'note' in ing else '' + ingredient.note = ing['note'].strip() if 'note' in ing else '' ingredient.save() step.ingredients.add(ingredient)