instapaper links

This commit is contained in:
Dima Gerasimov 2019-03-11 17:29:20 +00:00
parent b63a15e6aa
commit 3ec273729c

View file

@ -21,12 +21,22 @@ class Highlight(NamedTuple):
url: str url: str
title: str title: str
@property
def instapaper_link(self) -> str:
return f'https://www.instapaper.com/read/{self.bid}/{self.uid}'
class Bookmark(NamedTuple): class Bookmark(NamedTuple):
bid: Bid bid: Bid
time: int dt: datetime
url: str url: str
title: str title: str
@property
def instapaper_link(self) -> str:
return f'https://www.instapaper.com/read/{self.bid}'
class Page(NamedTuple): class Page(NamedTuple):
bookmark: Bookmark bookmark: Bookmark
highlights: List[Highlight] highlights: List[Highlight]
@ -37,6 +47,11 @@ def get_files():
def dkey(x): def dkey(x):
return lambda d: d[x] return lambda d: d[x]
def make_dt(time) -> datetime:
return pytz.utc.localize(datetime.utcfromtimestamp(time))
def get_stuff(all=True): def get_stuff(all=True):
all_bks: Dict[Bid, Bookmark] = OrderedDict() all_bks: Dict[Bid, Bookmark] = OrderedDict()
all_hls: Dict[Hid, Highlight] = OrderedDict() all_hls: Dict[Hid, Highlight] = OrderedDict()
@ -51,7 +66,7 @@ def get_stuff(all=True):
# TODO shit, ok progress can change apparently # TODO shit, ok progress can change apparently
all_bks[bid] = Bookmark( all_bks[bid] = Bookmark(
bid=bid, bid=bid,
time=b['time'], dt=make_dt(b['time']),
url=b['url'], url=b['url'],
title=b['title'], title=b['title'],
) )
@ -61,11 +76,10 @@ def get_stuff(all=True):
bid = str(h['bookmark_id']) bid = str(h['bookmark_id'])
# TODO just reference to bookmark in hightlight? # TODO just reference to bookmark in hightlight?
bk = all_bks[bid] bk = all_bks[bid]
dt = pytz.utc.localize(datetime.utcfromtimestamp(h['time']))
h = Highlight( h = Highlight(
uid=hid, uid=hid,
bid=bk.bid, bid=bk.bid,
dt=dt, dt=make_dt(h['time']),
text=h['text'], text=h['text'],
note=h['note'], note=h['note'],
url=bk.url, url=bk.url,