replace common fractions with their concrete value (else parsing is not possible)

This commit is contained in:
Patrick Pirker
2021-03-03 22:27:32 +01:00
committed by smilerz
parent 7414033495
commit 1690abaf47

View File

@@ -53,23 +53,11 @@ def get_from_scraper(scrape, space):
except (AttributeError, TypeError, SchemaOrgException): except (AttributeError, TypeError, SchemaOrgException):
recipe_json['image'] = '' recipe_json['image'] = ''
keywords = [] for x in ld_json['recipeIngredient']:
if x.replace(' ', '') != '':
x = x.replace('½', "0.5").replace('¼', "0.25").replace('¾', "0.75")
try: try:
if scrape.schema.data.get("keywords"): amount, unit, ingredient, note = parse_ingredient(x)
keywords += listify_keywords(scrape.schema.data.get("keywords"))
if scrape.schema.data.get('recipeCategory'):
keywords += listify_keywords(scrape.schema.data.get("recipeCategory"))
if scrape.schema.data.get('recipeCuisine'):
keywords += listify_keywords(scrape.schema.data.get("recipeCuisine"))
recipe_json['keywords'] = parse_keywords(list(set(map(str.casefold, keywords))), space)
except AttributeError:
recipe_json['keywords'] = keywords
try:
ingredients = []
for x in scrape.ingredients():
try:
amount, unit, ingredient, note = parse_single_ingredient(x)
if ingredient: if ingredient:
ingredients.append( ingredients.append(
{ {
@@ -86,6 +74,22 @@ def get_from_scraper(scrape, space):
'original': x 'original': x
} }
) )
except Exception:
ingredients.append(
{
'amount': amount,
'unit': {
'text': unit,
'id': random.randrange(10000, 99999)
},
'ingredient': {
'text': ingredient,
'id': random.randrange(10000, 99999)
},
'note': note,
'original': x
}
)
except Exception: except Exception:
ingredients.append( ingredients.append(
{ {