Skip to content

Instantly share code, notes, and snippets.

@macolyte
Created November 15, 2012 21:52
Show Gist options
  • Save macolyte/4081568 to your computer and use it in GitHub Desktop.
Save macolyte/4081568 to your computer and use it in GitHub Desktop.
pinboard_reading_list
import os
import markdown
import requests
import webbrowser
pinToken = 'Put your Pinboard API token here'
pinAPI = 'api.pinboard.in/v1/'
pinGet = 'posts/all'
pinURL = 'https://' + pinAPI + pinGet + '?auth_token=' + pinToken + '&toread=yes&format=json'
def main():
j = requests.get(pinURL).json
s = ""
for article in j:
outstring = "* [%s](%s)\n" % (article['description'], article['href'])
s += outstring
md = markdown.Markdown()
contents = md.convert(s)
with open('reading_list.html', 'w') as f:
f.write(contents)
pth = "file:///" + os.path.join(os.path.dirname(os.path.abspath(__file__)), "reading_list.html")
webbrowser.open(pth)
if __name__ == '__main__':
main()
@dlo
Copy link

dlo commented Jan 25, 2013

NB: I write a Pinboard client for iPhone called Pushpin.

You mentioned there's no way to mark as read with the API--there is. Just "add" a new bookmark with the same attributes as the original payload, with the exception of the "toread" parameter. E.g.

import urllib

bookmarks = requests.get(pinURL).json
for bookmark in bookmarks:
    bookmark['toread'] = "no"
    url = "https://api.pinboard.in/v1/posts/add?auth_token={}&{}".format(pinToken, urllib.urlencode(bookmark))
    requests.get(url)

P.S. Gotta use four spaces: http://www.python.org/dev/peps/pep-0008/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment