From 13115a1e539795e08c3e8c8ff2d9bad8a1201118 Mon Sep 17 00:00:00 2001 From: smilerz Date: Wed, 5 Jan 2022 17:49:38 -0600 Subject: [PATCH] fixes 1176 --- cookbook/helper/recipe_url_import.py | 11 +++++++---- cookbook/views/api.py | 11 ++++++++++- requirements.txt | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cookbook/helper/recipe_url_import.py b/cookbook/helper/recipe_url_import.py index 547ed2e40..283979fb6 100644 --- a/cookbook/helper/recipe_url_import.py +++ b/cookbook/helper/recipe_url_import.py @@ -1,13 +1,15 @@ import random import re +from html import unescape + +from django.utils.dateparse import parse_duration from isodate import parse_duration as iso_parse_duration from isodate.isoerror import ISO8601Error +from recipe_scrapers._utils import get_minutes +from cookbook.helper import recipe_url_import as helper from cookbook.helper.ingredient_parser import IngredientParser from cookbook.models import Keyword -from django.utils.dateparse import parse_duration -from html import unescape -from recipe_scrapers._utils import get_minutes def get_from_scraper(scrape, request): @@ -96,8 +98,9 @@ def get_from_scraper(scrape, request): recipe_json['keywords'] = keywords ingredient_parser = IngredientParser(request, True) + + ingredients = [] try: - ingredients = [] for x in scrape.ingredients(): try: amount, unit, ingredient, note = ingredient_parser.parse(x) diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 11a5d8ce2..dc28a7223 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -916,7 +916,16 @@ def recipe_from_source(request): }, status=400 ) - if len(scrape.ingredients()) and len(scrape.instructions()) == 0: + + try: + instructions = scrape.instructions() + except Exception: + instructions = "" + try: + ingredients = scrape.ingredients() + except Exception: + ingredients = [] + if len(ingredients) + len(instructions) == 0: return JsonResponse( { 'error': True, diff --git a/requirements.txt b/requirements.txt index 64c3b7d1f..31a5f2ff9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,7 +30,7 @@ Jinja2==3.0.3 django-webpack-loader==1.4.1 django-js-reverse==0.9.1 django-allauth==0.46.0 -recipe-scrapers==13.7.0 +recipe-scrapers==13.10.1 django-scopes==1.2.0 pytest==6.2.5 pytest-django==4.5.1 @@ -41,4 +41,4 @@ boto3==1.20.19 django-prometheus==2.1.0 django-hCaptcha==0.1.0 python-ldap==3.4.0 -django-auth-ldap==3.0.0 \ No newline at end of file +django-auth-ldap==3.0.0