add notify
This commit is contained in:
25
foods
25
foods
@@ -947,6 +947,19 @@ Oil 80g
|
|||||||
Potato 1000g
|
Potato 1000g
|
||||||
SweetPotato 450g
|
SweetPotato 450g
|
||||||
|
|
||||||
|
RoastedVeggies2
|
||||||
|
Broccoli 300g
|
||||||
|
Oil 70g
|
||||||
|
Potato 1000g
|
||||||
|
SweetPotato 300g
|
||||||
|
|
||||||
|
RoastedVeggies3
|
||||||
|
Broccoli 180g
|
||||||
|
Potato 510g
|
||||||
|
Carrot 160g
|
||||||
|
SweetPotato 310g
|
||||||
|
Oil 120g
|
||||||
|
|
||||||
OmletteWithoutMilk
|
OmletteWithoutMilk
|
||||||
Cheese 25g
|
Cheese 25g
|
||||||
Egg 180g
|
Egg 180g
|
||||||
@@ -1108,12 +1121,6 @@ Milk 400g
|
|||||||
Egg 195g
|
Egg 195g
|
||||||
Flour 70g
|
Flour 70g
|
||||||
|
|
||||||
RoastedVeggies2
|
|
||||||
Broccoli 300g
|
|
||||||
Oil 70g
|
|
||||||
Potato 1000g
|
|
||||||
SweetPotato 300g
|
|
||||||
|
|
||||||
BeanitHarkisVeggies
|
BeanitHarkisVeggies
|
||||||
Oil 60g
|
Oil 60g
|
||||||
BeanitHarkis 250g
|
BeanitHarkis 250g
|
||||||
@@ -1205,3 +1212,9 @@ Egg 325g
|
|||||||
Oil 20g
|
Oil 20g
|
||||||
Flour 20g
|
Flour 20g
|
||||||
Cheese 45g
|
Cheese 45g
|
||||||
|
|
||||||
|
VegeKotlet4
|
||||||
|
HarkisRouheseos 350g
|
||||||
|
SkimMilk 400g
|
||||||
|
Egg 260g
|
||||||
|
Flour 60g
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ from datetime import datetime
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
|
|
||||||
|
from common import format_timestamp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
current_date = datetime.now().strftime('%Y-%m-%d')
|
current_date = datetime.now().strftime('%Y-%m-%d')
|
||||||
current_time = datetime.now().strftime('%H:%M:%S')
|
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
|
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.write_text(f'''\
|
||||||
# {target_page.stem}
|
# {target_page.stem}
|
||||||
|
|
||||||
@@ -34,6 +59,9 @@ Godword:
|
|||||||
|
|
||||||
Habits:
|
Habits:
|
||||||
{habits}
|
{habits}
|
||||||
|
|
||||||
|
Notifications:
|
||||||
|
{notifications_rendered}
|
||||||
''')
|
''')
|
||||||
|
|
||||||
with open(target_page, 'a') as fp:
|
with open(target_page, 'a') as fp:
|
||||||
|
|||||||
6
parse.py
6
parse.py
@@ -100,6 +100,11 @@ def parse_exercise(block):
|
|||||||
|
|
||||||
return {'kind': 'INVALID'}
|
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):
|
def create_entry_module_parser(name, handler=None):
|
||||||
handler = handler or (lambda b: {'value': b.removeprefix(f'@{name} ')})
|
handler = handler or (lambda b: {'value': b.removeprefix(f'@{name} ')})
|
||||||
return lambda b: {'type': name} | handler(b)
|
return lambda b: {'type': name} | handler(b)
|
||||||
@@ -116,6 +121,7 @@ entry_modules = {
|
|||||||
'stop': create_entry_module_parser('stop', parse_timer),
|
'stop': create_entry_module_parser('stop', parse_timer),
|
||||||
'done': create_entry_module_parser('done', parse_timer),
|
'done': create_entry_module_parser('done', parse_timer),
|
||||||
'exercise': create_entry_module_parser('exercise', parse_exercise),
|
'exercise': create_entry_module_parser('exercise', parse_exercise),
|
||||||
|
'notify': create_entry_module_parser('notify', parse_notify),
|
||||||
}
|
}
|
||||||
|
|
||||||
def parse_entry(entry):
|
def parse_entry(entry):
|
||||||
|
|||||||
Reference in New Issue
Block a user