Permalink
Browse files

Merge pull request #3 from borwick/master

Check links for errors, add a new tag to processed links, and max # articles
  • Loading branch information...
anoved committed Dec 14, 2014
2 parents daae320 + fb0bf06 commit 2bb0bd7b762254ca770b8e3fd6f25f9509e1b012
Showing with 37 additions and 9 deletions.
  1. +35 −9 Pinboard.recipe
  2. +2 −0 Readme.md
@@ -16,6 +16,18 @@ apitoken = ''
#
delete_bookmarks = False
#
# How many articles to pull at most? Set to False for no checks.
#
max_articles = 15
#
# Should processed articles receive a tag? If so, set the tag:
#
processed_tag = 'calibre-recipe'
from calibre.web.feeds.news import BasicNewsRecipe
import urllib
import json
@@ -42,25 +54,39 @@ class PinboardRecipe(BasicNewsRecipe):
if len(bookmarks) == 0:
self.abort_recipe_processing('No unread Pinboard bookmarks.')
successful_bookmark_reads = 0
articles = []
for bookmark in bookmarks:
articles.append({
try:
urllib.urlopen(bookmark['href'])
articles.append({
'title': bookmark['description'],
'url': bookmark['href'],
'description': bookmark['extended'],
'date': bookmark['time']})
if delete_bookmarks:
params = urllib.urlencode({'url': bookmark['href'], 'auth_token': apitoken})
urllib.urlopen('https://api.pinboard.in/v1/posts/delete?' + params)
else:
# Mark bookmark as read by re-posting with 'toread' set to 'no'.
params = urllib.urlencode({
if delete_bookmarks:
params = urllib.urlencode({'url': bookmark['href'], 'auth_token': apitoken})
urllib.request.urlopen('https://api.pinboard.in/v1/posts/delete?' + params)
else:
if processed_tag:
bookmark['tags'] += ' {}'.format(processed_tag)
# Mark bookmark as read by re-posting with 'toread' set to 'no'.
params = urllib.urlencode({
'url': bookmark['href'], 'description': bookmark['description'],
'extended': bookmark['extended'], 'tags': bookmark['tags'],
'dt': bookmark['time'], 'shared': bookmark['shared'],
'replace': 'yes', 'toread': 'no', 'auth_token': apitoken})
urllib.urlopen('https://api.pinboard.in/v1/posts/add?' + params)
urllib.urlopen('https://api.pinboard.in/v1/posts/add?' + params)
successful_bookmark_reads += 1
if max_articles and successful_bookmark_reads >= max_articles:
break
except IOError:
continue
return [('Pinboard Bookmarks', articles)]
@@ -15,6 +15,8 @@ Setup
- In Calibre, select _Add a custom news source_ from the _Fetch news_ toolbar button or menu. Click _Load recipe from file_ and select the [`Pinboard.recipe`](https://raw.github.com/anoved/Pinboard-Recipe/master/Pinboard.recipe) file downloaded from this repository.
- Locate your [Pinboard API Token](https://pinboard.in/settings/password) and paste it into the _Pinboard Bookmarks_ source code as the `apitoken` value (indicated near the top of the script).
- By default, your unread bookmarks are marked as read once retrieved. If you would prefer to delete them instead, set the `delete_bookmarks` variable to `True`.
- By default, 15 links will be pulled per run. To pull all links, set the `max_articles` variable to `False`.
- By default, any links processed will receive a new tag, `calibre-recipe`. To change or remove this tag, set the `processed_tag` variable to False or a different string.
- Click _Add/Update recipe_ and click _Yes_ to confirm that you want to update ("replace") the recipe.
Now when you click _Fetch News_ you can choose _Pinboard Bookmarks_ from the _Custom_ section of the recipe list.

0 comments on commit 2bb0bd7

Please sign in to comment.