From 4244f403ed7206b95dbf77a1482720aed09ee986 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sun, 3 May 2020 08:22:15 +0100 Subject: [PATCH] simplify instapaper module --- my/instapaper.py | 51 +++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/my/instapaper.py b/my/instapaper.py index aa70527..1ad402a 100644 --- a/my/instapaper.py +++ b/my/instapaper.py @@ -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')