simplify instapaper module
This commit is contained in:
parent
81ca1e2c25
commit
4244f403ed
1 changed files with 14 additions and 37 deletions
|
@ -1,55 +1,32 @@
|
|||
"""
|
||||
Instapaper bookmarks, highlights and annotations
|
||||
"""
|
||||
from pathlib import Path
|
||||
from typing import NamedTuple, Optional, List, Iterator
|
||||
|
||||
from .common import group_by_key, PathIsh, get_files
|
||||
from .common import get_files
|
||||
|
||||
|
||||
from my.config import instapaper as config
|
||||
import my.config.repos.instapexport.dal as dal
|
||||
|
||||
|
||||
Highlight = dal.Highlight
|
||||
Bookmark = dal.Bookmark
|
||||
|
||||
|
||||
def _get_files():
|
||||
return get_files(config.export_path, glob='*.json')
|
||||
|
||||
|
||||
def get_dal() -> dal.DAL:
|
||||
def _dal() -> dal.DAL:
|
||||
return dal.DAL(_get_files())
|
||||
|
||||
|
||||
# TODO meh, come up with better name...
|
||||
class HighlightWithBm(NamedTuple):
|
||||
highlight: dal.Highlight
|
||||
bookmark: dal.Bookmark
|
||||
def pages():
|
||||
return _dal().pages()
|
||||
get_pages = pages # todo also deprecate..
|
||||
|
||||
|
||||
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]:
|
||||
# return list(iter_highlights(**kwargs))
|
||||
def get_pages():
|
||||
return get_dal().pages()
|
||||
|
||||
|
||||
|
||||
def get_todos() -> Iterator[HighlightWithBm]:
|
||||
def is_todo(hl: HighlightWithBm):
|
||||
h = hl.highlight
|
||||
note = h.note or ''
|
||||
note = note.lstrip().lower()
|
||||
return note.startswith('todo')
|
||||
return filter(is_todo, iter_highlights())
|
||||
|
||||
|
||||
def main():
|
||||
for h in get_todos():
|
||||
print(h)
|
||||
# TODO dunno, move this to private?
|
||||
def is_todo(hl: Highlight) -> bool:
|
||||
note = hl.note or ''
|
||||
note = note.lstrip().lower()
|
||||
return note.startswith('todo')
|
||||
|
|
Loading…
Add table
Reference in a new issue