Skip to content

Commit

Permalink
pocket: migrate to use HPI
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Jun 1, 2020
1 parent 5c42cea commit c8ffb93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 59 deletions.
66 changes: 8 additions & 58 deletions modules/pocket.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit c8ffb93

Please sign in to comment.