From c8ffb93d749cd920a93a191cd65e5ef90a728f6d Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Mon, 1 Jun 2020 17:10:15 +0100 Subject: [PATCH] pocket: migrate to use HPI --- modules/pocket.py | 66 ++++++----------------------------------------- tox.ini | 2 +- 2 files changed, 9 insertions(+), 59 deletions(-) diff --git a/modules/pocket.py b/modules/pocket.py index 613a5e4..5ccc34b 100755 --- a/modules/pocket.py +++ b/modules/pocket.py @@ -1,61 +1,15 @@ #!/usr/bin/env python3 -from datetime import datetime -from pathlib import Path -from typing import NamedTuple, Sequence, Any - -class Highlight(NamedTuple): - json: Any - - @property - def text(self) -> str: - return self.json['quote'] - - @property - def created(self) -> datetime: - return datetime.strptime(self.json['created_at'], '%Y-%m-%d %H:%M:%S') - - -class Article(NamedTuple): - json: Any - - @property - def url(self) -> str: - return self.json['given_url'] - - @property - def title(self) -> str: - return self.json['given_title'] - - @property - def pocket_link(self) -> str: - return 'https://app.getpocket.com/read/' + self.json['item_id'] - - @property - def added(self) -> datetime: - return datetime.fromtimestamp(int(self.json['time_added'])) - - @property - def highlights(self) -> Sequence[Highlight]: - raw = self.json.get('annotations', []) - return list(map(Highlight, raw)) - - # TODO add tags? - - -def get_articles(json_path: Path) -> Sequence[Article]: - import json - raw = json.loads(json_path.read_text())['list'] - return list(map(Article, raw.values())) - -from orger import StaticView +from orger import Mirror from orger.inorganic import node, link from orger.common import dt_heading +# TODO add tags? +from my.pocket import articles + -class PocketView(StaticView): - def get_items(self): - export_file = self.cmdline_args.file - for a in get_articles(export_file): +class PocketMirror(Mirror): + def get_items(self) -> Mirror.Results: + for a in articles(): yield node( heading=dt_heading( a.added, @@ -67,9 +21,5 @@ def get_items(self): ) -def setup_parser(p): - p.add_argument('--file', type=Path, help='JSON file from API export', required=True) - - if __name__ == '__main__': - PocketView.main(setup_parser=setup_parser) + PocketMirror.main() diff --git a/tox.ini b/tox.ini index 6f61c93..c193b21 100644 --- a/tox.ini +++ b/tox.ini @@ -33,7 +33,7 @@ commands = -p modules.pdfs \ -p modules.pinboard \ -p modules.pocket_demo \ - -p modules.pocket \ + # -p modules.pocket \ -p modules.polar \ # -p modules.reddit_all \ # -p modules.reddit \