This commit is contained in:
olari
2021-06-01 12:53:48 +03:00
parent 6e07d120a2
commit 557df1bb20
6 changed files with 101 additions and 1199 deletions

View File

@@ -1,24 +1,20 @@
from pathlib import Path
from subprocess import run
import re
import sys
import json
entry_re = re.compile(r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})', re.MULTILINE)
from common import format_timestamp
journal = json.load(open('journal.json'))
matches = []
keyword = sys.argv[1].lower()
for fpath in sorted((Path.home() / 'workspace' / 'journal').glob('*.md')):
header, *tmp = entry_re.split(fpath.read_text())
entries = list(zip(tmp[::2], tmp[1::2]))
for (timestamp, content) in sorted(entries, key=lambda x: x[0]):
content = '\n'.join(
part.replace('\n', ' ')
for part in content.split('\n\n')
)
if sys.argv[1].lower() in content.lower().split():
matches.append((timestamp, content))
for day, obj in journal.items():
for entry in obj['entries']:
for block in entry['blocks']:
if isinstance(block, str):
if keyword in block.lower().split():
matches.append((format_timestamp(entry['timestamp']), block))
buf = ''