# TODO add tags? class DAL: def __init__(self, sources: Sequence[PathIsh]) -> None: self.sources = list(map(Path, sources)) def raw(self) -> Json: last = max(self.sources) # TODO not sure if worth elaborate merging logic? return json.loads(last.read_text()) def articles(self) -> Iterator[Article]: yield from map(Article, self.raw()['list'].values()) def demo(dal: DAL) -> None: articles = list(dal.articles()) for a in articles: x = f""" {a.title} {len(a.highlights)} highlights {a.pocket_link} """.lstrip() print(x) if __name__ == '__main__': dal_helper.main(DAL=DAL, demo=demo)
return name @property def thread_id(self) -> str: return self.row['uid'] def iter_messages(self, order_by='timestamp') -> Iterator[Message]: for row in self.mt.find(thread_id=self.thread_id, order_by=order_by): yield Message(row=row, thread=self) class DAL: def __init__(self, db_path: Union[Path, str]) -> None: self.db = dataset.connect('sqlite:///{}'.format(db_path)) self.tt = self.db['threads'] self.mt = self.db['messages'] def iter_threads(self, order_by='name') -> Iterator[Thread]: for row in self.tt.all(order_by=order_by): yield Thread(mt=self.mt, row=row) def demo(dal: DAL): for t in dal.iter_threads(): msgs = list(t.iter_messages()) print(f"Conversation with {t.name}: {len(msgs)} messages") if __name__ == '__main__': dal_helper.main(DAL=DAL, demo=demo, single_source=True)