final commit

This commit is contained in:
olari
2021-05-24 05:37:47 +03:00
parent bdaeb1fb95
commit 0e1fd8b4a9
5 changed files with 362 additions and 0 deletions

29
search.py Normal file
View File

@@ -0,0 +1,29 @@
from pathlib import Path
from subprocess import run
import re
import sys
entry_re = re.compile(r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})', re.MULTILINE)
matches = []
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))
buf = ''
for (ts, c) in matches:
c = c.replace('\n', ' ').strip()
buf += (f'[[{ts}]] {c}')[:80] + '\n'
run(['nvim', '-'], input=buf.encode('utf-8'))