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
|
Instapaper bookmarks, highlights and annotations
|
||||||
"""
|
"""
|
||||||
from pathlib import Path
|
from .common import get_files
|
||||||
from typing import NamedTuple, Optional, List, Iterator
|
|
||||||
|
|
||||||
from .common import group_by_key, PathIsh, get_files
|
|
||||||
|
|
||||||
|
|
||||||
from my.config import instapaper as config
|
from my.config import instapaper as config
|
||||||
import my.config.repos.instapexport.dal as dal
|
import my.config.repos.instapexport.dal as dal
|
||||||
|
|
||||||
|
|
||||||
|
Highlight = dal.Highlight
|
||||||
|
Bookmark = dal.Bookmark
|
||||||
|
|
||||||
|
|
||||||
def _get_files():
|
def _get_files():
|
||||||
return get_files(config.export_path, glob='*.json')
|
return get_files(config.export_path, glob='*.json')
|
||||||
|
|
||||||
|
|
||||||
def get_dal() -> dal.DAL:
|
def _dal() -> dal.DAL:
|
||||||
return dal.DAL(_get_files())
|
return dal.DAL(_get_files())
|
||||||
|
|
||||||
|
|
||||||
# TODO meh, come up with better name...
|
def pages():
|
||||||
class HighlightWithBm(NamedTuple):
|
return _dal().pages()
|
||||||
highlight: dal.Highlight
|
get_pages = pages # todo also deprecate..
|
||||||
bookmark: dal.Bookmark
|
|
||||||
|
|
||||||
|
|
||||||
def iter_highlights(**kwargs) -> Iterator[HighlightWithBm]:
|
# TODO dunno, move this to private?
|
||||||
# meh...
|
def is_todo(hl: Highlight) -> bool:
|
||||||
dl = get_dal()
|
note = hl.note or ''
|
||||||
hls = dl.highlights()
|
note = note.lstrip().lower()
|
||||||
bms = dl.bookmarks()
|
return note.startswith('todo')
|
||||||
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)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue