fixes 1176

This commit is contained in:
smilerz
2022-01-05 17:49:38 -06:00
parent af9a2a89ec
commit 13115a1e53
3 changed files with 19 additions and 7 deletions

View File

@@ -1,13 +1,15 @@
import random import random
import re import re
from html import unescape
from django.utils.dateparse import parse_duration
from isodate import parse_duration as iso_parse_duration from isodate import parse_duration as iso_parse_duration
from isodate.isoerror import ISO8601Error 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.helper.ingredient_parser import IngredientParser
from cookbook.models import Keyword 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): def get_from_scraper(scrape, request):
@@ -96,8 +98,9 @@ def get_from_scraper(scrape, request):
recipe_json['keywords'] = keywords recipe_json['keywords'] = keywords
ingredient_parser = IngredientParser(request, True) ingredient_parser = IngredientParser(request, True)
ingredients = []
try: try:
ingredients = []
for x in scrape.ingredients(): for x in scrape.ingredients():
try: try:
amount, unit, ingredient, note = ingredient_parser.parse(x) amount, unit, ingredient, note = ingredient_parser.parse(x)

View File

@@ -916,7 +916,16 @@ def recipe_from_source(request):
}, },
status=400 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( return JsonResponse(
{ {
'error': True, 'error': True,

View File

@@ -30,7 +30,7 @@ Jinja2==3.0.3
django-webpack-loader==1.4.1 django-webpack-loader==1.4.1
django-js-reverse==0.9.1 django-js-reverse==0.9.1
django-allauth==0.46.0 django-allauth==0.46.0
recipe-scrapers==13.7.0 recipe-scrapers==13.10.1
django-scopes==1.2.0 django-scopes==1.2.0
pytest==6.2.5 pytest==6.2.5
pytest-django==4.5.1 pytest-django==4.5.1
@@ -41,4 +41,4 @@ boto3==1.20.19
django-prometheus==2.1.0 django-prometheus==2.1.0
django-hCaptcha==0.1.0 django-hCaptcha==0.1.0
python-ldap==3.4.0 python-ldap==3.4.0
django-auth-ldap==3.0.0 django-auth-ldap==3.0.0