This commit is contained in:
olari
2021-06-01 12:53:48 +03:00
parent 6e07d120a2
commit 557df1bb20
6 changed files with 101 additions and 1199 deletions

View File

@@ -4,6 +4,9 @@ from datetime import datetime
def parse_timestamp(timestamp):
return datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
def format_timestamp(timestamp):
return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
def parse_foods_file():
path = Path.home() / 'projects' / 'open-journal' / 'foods'
text = path.read_text()
@@ -79,4 +82,22 @@ def parse_foods_file():
return foods, recipes
def evaluate_food_entry(foods, recipes, value, name):
if name in recipes:
food = recipes[name]
if value == 0.0:
value = food['TOTAL']
food = {k: v*(value/food['TOTAL']) for k,v in food.items()}
elif name in foods:
if value == 0.0:
value = 100
food = {k: v*(value/100.0) for k,v in foods[name].items()}
else:
breakpoint()
print(f'ERROR: Invalid diet entry: {content}')
return food