mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
fraction import
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import unicodedata
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
|
|
||||||
import microdata
|
import microdata
|
||||||
@@ -74,13 +75,19 @@ def find_recipe_json(ld_json, url):
|
|||||||
amount = 0
|
amount = 0
|
||||||
unit = ''
|
unit = ''
|
||||||
if len(ingredient_split) > 2:
|
if len(ingredient_split) > 2:
|
||||||
|
|
||||||
ingredient = " ".join(ingredient_split[2:])
|
ingredient = " ".join(ingredient_split[2:])
|
||||||
unit = ingredient_split[1]
|
unit = ingredient_split[1]
|
||||||
try:
|
|
||||||
amount = float(ingredient_split[0].replace(',', '.'))
|
if 'fraction' in unicodedata.decomposition(ingredient_split[0]):
|
||||||
except ValueError:
|
frac_split = unicodedata.decomposition(ingredient_split[0]).split()
|
||||||
amount = 0
|
amount = round(float((frac_split[1]).replace('003', '')) / float((frac_split[3]).replace('003', '')), 3)
|
||||||
ingredient = " ".join(ingredient_split)
|
else:
|
||||||
|
try:
|
||||||
|
amount = float(ingredient_split[0].replace(',', '.'))
|
||||||
|
except ValueError:
|
||||||
|
amount = 0
|
||||||
|
ingredient = " ".join(ingredient_split)
|
||||||
if len(ingredient_split) == 2:
|
if len(ingredient_split) == 2:
|
||||||
ingredient = " ".join(ingredient_split[1:])
|
ingredient = " ".join(ingredient_split[1:])
|
||||||
unit = ''
|
unit = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user