Jake.codes

Post to Pinboard, for Pythonista

Monday, January 14, 2013

# -*- coding: utf-8 -*-
# Post to Pinboard with Speed
# By Jake Bilbrey - jakebilbrey.com
#
# Use your Pinboard
# API Token to post to
# your Pinboard account.
#
import console
import requests
import clipboard
import re
import urllib
import bs4
import webbrowser

# Get your toke at:
# http://pinboard.in/settings/password
token = ""

console.clear()
try:
    if re.match('\Ahttp', clipboard.get()):
        url = clipboard.get()
        title = bs4.BeautifulSoup(urllib.urlopen(url)).select('title')[0](text=True)[0]
    else:
        url = console.input_alert("URL to Pinboard")
        title = bs4.BeautifulSoup(urllib.urlopen(url)).select('title')[0](text=True)[0]
    
    query = 'https://api.pinboard.in/v1/posts/add?auth_token=' + token + '&url=' + url + '&description=' + title + '&tags=later'
    pinboard = bs4.BeautifulSoup(urllib.urlopen(query))
    print 'Added to Pinboard:'
    print title
    print url

except:
    console.clear()