playing around with pint
This commit is contained in:
@ -1,14 +1,17 @@
|
|||||||
def base_conversions():
|
from pint import UnitRegistry, UndefinedUnitError
|
||||||
METRIC_MASS_CONVERSIONS = {
|
|
||||||
'g': {'base_amount': 1000, 'base_unit': 'mg', 'converted_amount': 1, 'converted_unit': 'g'},
|
|
||||||
'mg': {'base_amount': 1000, 'base_unit': 'g', 'converted_amount': 1, 'converted_unit': 'kg'},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
def base_conversions(ingredient_list):
|
||||||
|
ingredient_list = [{'amount': 1, 'unit': 'g'}, {'amount': 1, 'unit': 'Gramm'}, {'amount': 1, 'unit': 'Stück'}]
|
||||||
|
ureg = UnitRegistry()
|
||||||
|
pint_converted_list = []
|
||||||
|
for i in ingredient_list:
|
||||||
|
try:
|
||||||
|
pint_converted_list.append(ureg.Quantity(f'{i["amount"]} {i["unit"]}'))
|
||||||
|
except UndefinedUnitError:
|
||||||
|
pass
|
||||||
|
|
||||||
METRIC_LIQUID_CONVERSIONS = [
|
print(pint_converted_list)
|
||||||
{'base_amount': 1000, 'base_unit': 'ml', 'converted_amount': 1, 'converted_unit': 'l'},
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def get_conversions(amount, unit, food):
|
def get_conversions(amount, unit, food):
|
||||||
|
@ -45,4 +45,5 @@ django-auth-ldap==4.1.0
|
|||||||
pytest-factoryboy==2.5.0
|
pytest-factoryboy==2.5.0
|
||||||
pyppeteer==1.0.2
|
pyppeteer==1.0.2
|
||||||
validators==0.20.0
|
validators==0.20.0
|
||||||
pytube==12.1.0
|
pytube==12.1.0
|
||||||
|
pint==0.20.1
|
Reference in New Issue
Block a user