Fix ingredient parsing for fractions using '/'

Even though ingredients like '1 1/2 something' already worked fine and got converted to 1.5 something
I just came across a recipe using '1/2' as the whole amount without any whole number before that.
Apparently I overlooked that case before so I now also fixed that.
This commit is contained in:
Aaron
2021-02-14 18:41:49 +01:00
parent 3e55207a8d
commit 87d6ca0200
2 changed files with 10 additions and 2 deletions

View File

@ -28,7 +28,7 @@ def parse_amount(x):
and (
x[end] in string.digits
or (
(x[end] == '.' or x[end] == ',')
(x[end] == '.' or x[end] == ',' or x[end] == '/')
and end + 1 < len(x)
and x[end + 1] in string.digits
)
@ -36,7 +36,10 @@ def parse_amount(x):
):
end += 1
if end > 0:
amount = float(x[:end].replace(',', '.'))
if "/" in x[:end]:
amount = parse_fraction(x[:end])
else:
amount = float(x[:end].replace(',', '.'))
else:
amount = parse_fraction(x[0])
end += 1