Fix highlights retrieving

This commit is contained in:
Dima Gerasimov 2020-01-07 08:23:03 +00:00
parent 5611fce720
commit ea4dcdafb0

View file

@ -42,8 +42,19 @@ def get_dal() -> dal.DAL:
return dal.DAL(_get_files()) return dal.DAL(_get_files())
def iter_highlights(**kwargs) -> Iterator[dal.Highlight]: # TODO meh, come up with better name...
return iter(get_dal().highlights().values()) class HighlightWithBm(NamedTuple):
highlight: dal.Highlight
bookmark: dal.Bookmark
def iter_highlights(**kwargs) -> Iterator[HighlightWithBm]:
# meh...
dl = get_dal()
hls = dl.highlights()
bms = dl.bookmarks()
for _, h in hls.items():
yield HighlightWithBm(highlight=h, bookmark=bms[h.bid])
# def get_highlights(**kwargs) -> List[Highlight]: # def get_highlights(**kwargs) -> List[Highlight]:
@ -52,12 +63,14 @@ def get_pages():
return get_dal().pages() return get_dal().pages()
def get_todos() -> List[dal.Highlight]:
def is_todo(h): def get_todos() -> Iterator[HighlightWithBm]:
def is_todo(hl: HighlightWithBm):
h = hl.highlight
note = h.note or '' note = h.note or ''
note = note.lstrip().lower() note = note.lstrip().lower()
return note.startswith('todo') return note.startswith('todo')
return list(filter(is_todo, iter_highlights())) return filter(is_todo, iter_highlights())
def test_get_todos(): def test_get_todos():