A Pinboard Reading List in Pythonista

After reading Viticci's tome on Pythonista last week, I finally decided to sit down and play around with the app a little bit. My first project was a relatively simple one: open a web browser with all of my Pinboard links that were marked as read later.

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()

Also available in gist form.

I drew some inspiration from the aforelinked script by Nick Wynja. I could have written out the HTML directly instead of having it go through the markdown module, but I wanted to see how it came out. It also won't let you mark the links as read because as far as I can tell there is no way to do that using the Pinboard API.

Share on App.net

Comments !

++useful

elsewhere