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,24 +53,28 @@ 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']:
try: if x.replace(' ', '') != '':
if scrape.schema.data.get("keywords"): x = x.replace('½', "0.5").replace('¼', "0.25").replace('¾', "0.75")
keywords += listify_keywords(scrape.schema.data.get("keywords")) try:
if scrape.schema.data.get('recipeCategory'): amount, unit, ingredient, note = parse_ingredient(x)
keywords += listify_keywords(scrape.schema.data.get("recipeCategory")) if ingredient:
if scrape.schema.data.get('recipeCuisine'): ingredients.append(
keywords += listify_keywords(scrape.schema.data.get("recipeCuisine")) {
recipe_json['keywords'] = parse_keywords(list(set(map(str.casefold, keywords))), space) 'amount': amount,
except AttributeError: 'unit': {
recipe_json['keywords'] = keywords 'text': unit,
'id': random.randrange(10000, 99999)
try: },
ingredients = [] 'ingredient': {
for x in scrape.ingredients(): 'text': ingredient,
try: 'id': random.randrange(10000, 99999)
amount, unit, ingredient, note = parse_single_ingredient(x) },
if ingredient: 'note': note,
'original': x
}
)
except Exception:
ingredients.append( ingredients.append(
{ {
'amount': amount, 'amount': amount,