add notify

This commit is contained in:
olari
2021-06-16 17:37:28 +03:00
parent d26ed919b7
commit bef8fec234
3 changed files with 53 additions and 6 deletions

25
foods
View File

@@ -947,6 +947,19 @@ Oil 80g
Potato 1000g
SweetPotato 450g
RoastedVeggies2
Broccoli 300g
Oil 70g
Potato 1000g
SweetPotato 300g
RoastedVeggies3
Broccoli 180g
Potato 510g
Carrot 160g
SweetPotato 310g
Oil 120g
OmletteWithoutMilk
Cheese 25g
Egg 180g
@@ -1108,12 +1121,6 @@ Milk 400g
Egg 195g
Flour 70g
RoastedVeggies2
Broccoli 300g
Oil 70g
Potato 1000g
SweetPotato 300g
BeanitHarkisVeggies
Oil 60g
BeanitHarkis 250g
@@ -1205,3 +1212,9 @@ Egg 325g
Oil 20g
Flour 20g
Cheese 45g
VegeKotlet4
HarkisRouheseos 350g
SkimMilk 400g
Egg 260g
Flour 60g

View File

@@ -3,6 +3,12 @@ from datetime import datetime
from pathlib import Path
import random
import sys
import json
from common import format_timestamp
current_date = datetime.now().strftime('%Y-%m-%d')
current_time = datetime.now().strftime('%H:%M:%S')
@@ -26,6 +32,25 @@ if not target_page.exists():
cwd=str(journal_path), stdout=DEVNULL, stderr=DEVNULL
)
journal = json.load(open('journal.json'))
notifications = []
for day, v in journal.items():
for entry in v.get('entries'):
for block in entry['blocks']:
if not isinstance(block, str) and block['type'] == 'notify':
if block['day'] == current_date:
notifications.append((
format_timestamp(entry['timestamp']),
block['message']
))
notifications_rendered = '\n'.join(
f'[[{entry}]] {message}'
for entry, message in notifications
)
target_page.write_text(f'''\
# {target_page.stem}
@@ -34,6 +59,9 @@ Godword:
Habits:
{habits}
Notifications:
{notifications_rendered}
''')
with open(target_page, 'a') as fp:

View File

@@ -100,6 +100,11 @@ def parse_exercise(block):
return {'kind': 'INVALID'}
def parse_notify(block):
tag, day, *rest = block.split()
return {'day': day.strip(), 'message': ' '.join(rest)}
def create_entry_module_parser(name, handler=None):
handler = handler or (lambda b: {'value': b.removeprefix(f'@{name} ')})
return lambda b: {'type': name} | handler(b)
@@ -116,6 +121,7 @@ entry_modules = {
'stop': create_entry_module_parser('stop', parse_timer),
'done': create_entry_module_parser('done', parse_timer),
'exercise': create_entry_module_parser('exercise', parse_exercise),
'notify': create_entry_module_parser('notify', parse_notify),
}
def parse_entry(entry):