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

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: