paprika importer improvements
This commit is contained in:
@ -255,6 +255,15 @@ def parse_servings(servings):
|
|||||||
return servings
|
return servings
|
||||||
|
|
||||||
|
|
||||||
|
def parse_servings_text(servings):
|
||||||
|
if type(servings) == str:
|
||||||
|
try:
|
||||||
|
servings = re.sub("\d+", '', servings).strip()
|
||||||
|
except Exception:
|
||||||
|
servings = ''
|
||||||
|
return servings
|
||||||
|
|
||||||
|
|
||||||
def parse_time(recipe_time):
|
def parse_time(recipe_time):
|
||||||
if type(recipe_time) not in [int, float]:
|
if type(recipe_time) not in [int, float]:
|
||||||
try:
|
try:
|
||||||
|
@ -6,6 +6,7 @@ from gettext import gettext as _
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from cookbook.helper.ingredient_parser import IngredientParser
|
from cookbook.helper.ingredient_parser import IngredientParser
|
||||||
|
from cookbook.helper.recipe_url_import import parse_servings, parse_servings_text
|
||||||
from cookbook.integration.integration import Integration
|
from cookbook.integration.integration import Integration
|
||||||
from cookbook.models import Ingredient, Keyword, Recipe, Step
|
from cookbook.models import Ingredient, Keyword, Recipe, Step
|
||||||
|
|
||||||
@ -26,10 +27,9 @@ class Paprika(Integration):
|
|||||||
recipe.description = '' if len(recipe_json['description'].strip()) > 500 else recipe_json['description'].strip()
|
recipe.description = '' if len(recipe_json['description'].strip()) > 500 else recipe_json['description'].strip()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if re.match(r'([0-9])+\s(.)*', recipe_json['servings']):
|
if 'servings' in recipe_json['servings']:
|
||||||
s = recipe_json['servings'].split(' ')
|
recipe.servings = parse_servings(recipe_json['servings'])
|
||||||
recipe.servings = s[0]
|
recipe.servings_text = parse_servings_text(recipe_json['servings'])
|
||||||
recipe.servings_text = s[1]
|
|
||||||
|
|
||||||
if len(recipe_json['cook_time'].strip()) > 0:
|
if len(recipe_json['cook_time'].strip()) > 0:
|
||||||
recipe.waiting_time = re.findall(r'\d+', recipe_json['cook_time'])[0]
|
recipe.waiting_time = re.findall(r'\d+', recipe_json['cook_time'])[0]
|
||||||
|
Reference in New Issue
Block a user