fraction import

This commit is contained in:
vabene1111
2020-12-14 19:56:21 +01:00
parent e7922a7e47
commit 9ea90f1c87

View File

@@ -1,6 +1,7 @@
import json
import random
import re
import unicodedata
from json import JSONDecodeError
import microdata
@@ -74,13 +75,19 @@ def find_recipe_json(ld_json, url):
amount = 0
unit = ''
if len(ingredient_split) > 2:
ingredient = " ".join(ingredient_split[2:])
unit = ingredient_split[1]
try:
amount = float(ingredient_split[0].replace(',', '.'))
except ValueError:
amount = 0
ingredient = " ".join(ingredient_split)
if 'fraction' in unicodedata.decomposition(ingredient_split[0]):
frac_split = unicodedata.decomposition(ingredient_split[0]).split()
amount = round(float((frac_split[1]).replace('003', '')) / float((frac_split[3]).replace('003', '')), 3)
else:
try:
amount = float(ingredient_split[0].replace(',', '.'))
except ValueError:
amount = 0
ingredient = " ".join(ingredient_split)
if len(ingredient_split) == 2:
ingredient = " ".join(ingredient_split[1:])
unit = ''