move pocket provider from orger demo
This commit is contained in:
parent
0b0a8c2afc
commit
9f35f0f69b
1 changed files with 48 additions and 0 deletions
48
my/pocket.py
Normal file
48
my/pocket.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
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?
|
||||||
|
|
||||||
|
|
||||||
|
# TODO integrate with my_configuration
|
||||||
|
def get_articles(json_path: Path) -> Sequence[Article]:
|
||||||
|
import json
|
||||||
|
raw = json.loads(json_path.read_text())['list']
|
||||||
|
return list(map(Article, raw.values()))
|
Loading…
Add table
Reference in a new issue