66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
from common import format_timestamp
|
|
import json
|
|
|
|
def generate_godword(value):
|
|
return f"{' '.join(value[:10])}\n{' '.join(value[10:])}"
|
|
|
|
def generate_habits(value):
|
|
return '\n'.join(f'[{"x" if v else "-"}] {k}' for k,v in value.items())
|
|
|
|
header_modules = {
|
|
'godword': generate_godword,
|
|
'habits': generate_habits,
|
|
}
|
|
|
|
def generate_diet(block):
|
|
_, amount, food = block.values()
|
|
return f'@diet {amount}g {food}'
|
|
|
|
def generate_exercise(block):
|
|
if block['kind'] == 'walk':
|
|
return f'@exercise {block["minutes"]}min {block["distance"]}km {block["steps"]}steps'
|
|
|
|
def generate_default(block):
|
|
return f'@{block["type"]} {block["value"]}'
|
|
|
|
def generate_timer(block):
|
|
return f'@{block["type"]} {format_timestamp(block["timestamp"])}'
|
|
|
|
entry_modules = {
|
|
'diet': generate_diet,
|
|
'exercise': generate_exercise,
|
|
'hide': lambda _: '@hide',
|
|
'post': generate_timer,
|
|
}
|
|
|
|
journal = json.load(open('journal.json'))
|
|
|
|
for curr_day in journal:
|
|
header, entries = journal[curr_day].values()
|
|
|
|
result = f'# {curr_day}\n'
|
|
|
|
for name, value in header.items():
|
|
result += f'\n{name.title()}:\n'
|
|
result += header_modules[name](value)
|
|
result += '\n'
|
|
|
|
def format_block(block):
|
|
if isinstance(block, str):
|
|
return block
|
|
else:
|
|
return entry_modules[block['type']](block)
|
|
|
|
for entry in entries:
|
|
result += f'\n{format_timestamp(entry["timestamp"])} '
|
|
if len(entry['blocks']) == 1:
|
|
result += f'{format_block(entry["blocks"][0])}\n'
|
|
else:
|
|
result += '\n'
|
|
for block in entry['blocks']:
|
|
result += f'\n{format_block(block)}\n'
|
|
|
|
print(result)
|
|
|
|
|