update
This commit is contained in:
26
search.py
26
search.py
@@ -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 = ''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user