Skip to content

Instantly share code, notes, and snippets.

@dustym
Created November 11, 2010 03:48
Show Gist options
  • Save dustym/671964 to your computer and use it in GitHub Desktop.
Save dustym/671964 to your computer and use it in GitHub Desktop.
Uses the deliciousapi library to grab a random saved pinboard.in url and pop it into instapaper. Needs the version of deliciousapi.py with the modified pinboard.in api endpoint at https://gist.github.com/671964/e592caf3732a35241b980866c386a58aff2e65a9
import deliciousapi
import random
import urllib
import ConfigParser
import os.path
class RandomDeliciousLink(object):
def __init__(self, pinboard_username, pinboard_password,
instapaper_username, instapaper_password):
self.pinboard_username = pinboard_username
self.pinboard_password = pinboard_password
self.instapaper_username = instapaper_username
self.instapaper_password = instapaper_password
def url(self):
dapi = deliciousapi.DeliciousAPI()
user = dapi.get_user(self.pinboard_username, self.pinboard_password)
bookmark_urls = []
for bookmark in user.bookmarks:
bookmark_urls.append(bookmark[0])
random_idx = random.randint(0,len(bookmark_urls))
return bookmark_urls[random_idx]
def post(self):
url = self.url()
data = {
'url': url,
'username': self.instapaper_username,
'password': self.instapaper_password
}
data = urllib.urlencode(data)
response = urllib.urlopen('https://www.instapaper.com/api/add', data=data)
return response.read()
if __name__ == "__main__":
config = ConfigParser.ConfigParser()
path = os.path.expanduser('~/.auth')
config.read(path)
pu = config.get('pinboard','username')
pp = config.get('pinboard','password')
iu = config.get('instapaper','username')
ip = config.get('instapaper','password')
link = RandomDeliciousLink(pinboard_username=pu, pinboard_password=pp,
instapaper_username=iu, instapaper_password=ip)
link.post()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment