Skip to content

Commit

Permalink
modules.pinboard: update to support error handling, sort items properly
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Nov 6, 2023
1 parent 756295b commit 54ea450
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/orger/modules/pinboard.py
Original file line number Diff line number Diff line change
@@ -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__':
Expand Down

0 comments on commit 54ea450

Please sign in to comment.