From 3ec273729c4ae4c301ed194a03390f163054ec2c Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Mon, 11 Mar 2019 17:29:20 +0000 Subject: [PATCH] instapaper links --- instapaper/__init__.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/instapaper/__init__.py b/instapaper/__init__.py index 686da34..05e9fd7 100644 --- a/instapaper/__init__.py +++ b/instapaper/__init__.py @@ -21,12 +21,22 @@ class Highlight(NamedTuple): url: str title: str + @property + def instapaper_link(self) -> str: + return f'https://www.instapaper.com/read/{self.bid}/{self.uid}' + + class Bookmark(NamedTuple): bid: Bid - time: int + dt: datetime url: str title: str + @property + def instapaper_link(self) -> str: + return f'https://www.instapaper.com/read/{self.bid}' + + class Page(NamedTuple): bookmark: Bookmark highlights: List[Highlight] @@ -37,6 +47,11 @@ def get_files(): def dkey(x): return lambda d: d[x] + +def make_dt(time) -> datetime: + return pytz.utc.localize(datetime.utcfromtimestamp(time)) + + def get_stuff(all=True): all_bks: Dict[Bid, Bookmark] = OrderedDict() all_hls: Dict[Hid, Highlight] = OrderedDict() @@ -51,7 +66,7 @@ def get_stuff(all=True): # TODO shit, ok progress can change apparently all_bks[bid] = Bookmark( bid=bid, - time=b['time'], + dt=make_dt(b['time']), url=b['url'], title=b['title'], ) @@ -61,11 +76,10 @@ def get_stuff(all=True): bid = str(h['bookmark_id']) # TODO just reference to bookmark in hightlight? bk = all_bks[bid] - dt = pytz.utc.localize(datetime.utcfromtimestamp(h['time'])) h = Highlight( uid=hid, bid=bk.bid, - dt=dt, + dt=make_dt(h['time']), text=h['text'], note=h['note'], url=bk.url,