mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-04 13:48:32 -05:00
Merge branch 'master' into develop
# Conflicts: # requirements.txt
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -1000,7 +1000,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,
|
||||||
|
|||||||
Reference in New Issue
Block a user