From 54ea450bb8a4fa6ffdf21237a38b08830cd6201e Mon Sep 17 00:00:00 2001 From: karlicoss Date: Mon, 6 Nov 2023 23:13:21 +0000 Subject: [PATCH] modules.pinboard: update to support error handling, sort items properly --- src/orger/modules/pinboard.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/orger/modules/pinboard.py b/src/orger/modules/pinboard.py index 9f88bc9..11aafce 100755 --- a/src/orger/modules/pinboard.py +++ b/src/orger/modules/pinboard.py @@ -1,26 +1,38 @@ #!/usr/bin/env python3 +from typing import List + from orger import Mirror +from orger.common import dt_heading, error from orger.inorganic import node, link -from orger.common import dt_heading import my.pinboard as pinboard class PinboardView(Mirror): def get_items(self) -> Mirror.Results: - from orger.inorganic import OrgNode - def make_item(b: pinboard.Bookmark) -> OrgNode: - return node( + items: List[pinboard.Bookmark] = [] + for b in pinboard.bookmarks(): + if isinstance(b, Exception): + yield error(b) + else: + items.append(b) + + for b in sorted( + items, + # need to sort by some other property since all initial exports have the same timestamp + # doesn't look like there is any sort of bookmark id for pinboard + key=lambda b: (b.created, b.url), + ): + yield node( heading=dt_heading(b.created, link(title=b.title, url=b.url)), body=b.description, tags=b.tags, ) - return [make_item(b) for b in pinboard.bookmarks()] test = PinboardView.make_test( heading='Cartesian Closed Comic #21', - contains='doctorwho', # todo predicate? + contains='doctorwho', # todo predicate? ) if __name__ == '__main__':