prepare for upload

This commit is contained in:
olari
2021-05-14 19:53:44 +03:00
parent ea61d14250
commit ca7ce0e37c
2 changed files with 112 additions and 28 deletions

View File

@@ -5,6 +5,8 @@ from functools import reduce
import re
import string
import sys
def parse_foods_file():
path = Path.home() / 'projects' / 'open-journal' / 'foods'
text = path.read_text()
@@ -70,7 +72,7 @@ def parse_foods_file():
for k,v in mm.items():
calories += v * {
'Carbs': 4,
'Fat': 8,
'Fat': 9,
'Protein': 4
}.get(k, 0.0)
return calories
@@ -82,6 +84,32 @@ def parse_foods_file():
foods, recipes = parse_foods_file()
if len(sys.argv) > 1:
value, name = sys.argv[1:]
value = float(value.removesuffix('g'))
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}')
from pprint import pprint
pprint(food)
exit(0)
entry_re = re.compile(r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ', re.MULTILINE)
diet_re = re.compile(r'@diet (\d+g) ([a-zA-Z]+)')
@@ -91,7 +119,7 @@ total_words = 0
word_frequency = Counter()
total_csv = [['day', 'entries', 'words']]
daily_csv = [['day', 'entries', 'words', 'calories']]
daily_csv = [['day', 'entries', 'words', 'calories', 'protein']]
entry_csv = [['timestamp', 'words']]
words_csv = [['word', 'count']]
@@ -108,6 +136,7 @@ for fpath in sorted((Path.home() / 'workspace' / 'journal').glob('*.md')):
daily_entries = len(entries)
daily_words = 0
daily_calories = 0.0
daily_protein = 0.0
for (timestamp, content) in sorted(entries, key=lambda x: x[0]):
timestamp = int(datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S').timestamp())
@@ -153,6 +182,7 @@ for fpath in sorted((Path.home() / 'workspace' / 'journal').glob('*.md')):
))
daily_calories += food.get('Energy', 0.0)
daily_protein += food.get('Protein', 0.0)
words = ''.join(
c if c in string.ascii_letters+"'" else ' '
@@ -166,7 +196,8 @@ for fpath in sorted((Path.home() / 'workspace' / 'journal').glob('*.md')):
entry_csv.append([timestamp, entry_words])
daily_csv.append([day, daily_entries, daily_words, daily_calories])
daily_csv.append([day, daily_entries, daily_words, daily_calories,
daily_protein])
total_entries += daily_entries
total_words += daily_words