Skip to content

Instantly share code, notes, and snippets.

@srid
Forked from sdb/ril2ip.py
Created November 21, 2011 04:15
Show Gist options
  • Save srid/1381594 to your computer and use it in GitHub Desktop.
Save srid/1381594 to your computer and use it in GitHub Desktop.
copy bookmarks from Read It Later to Instapaper (fixed)
#! /usr/bin/env python
"""
Script to copy all bookmarks from Read It Later to Instapaper.
See also http://readitlaterlist.com/api/docs/#get
and http://www.instapaper.com/api/simple
"""
import urllib, urllib2, json
RIL_ENDPOINT = 'https://readitlaterlist.com/v2'
IP_ENDPOINT = 'https://www.instapaper.com/api'
def open_url(url):
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
print('GET ' + url)
return opener.open(url)
def main(ril_api_key, ril_usr, ril_pwd, ip_usr, ip_pwd):
# fetch bookmarks from RIL as JSON
ril_query = urllib.urlencode({'username':ril_usr, 'password':ril_pwd,'apikey':ril_api_key})
ril_url = '%s/get?%s' %(RIL_ENDPOINT, ril_query)
f = open_url(ril_url)
bookmarks = json.loads(f.read())['list']
# import bookmarks into Instapaper
open_url('%s/authenticate?%s' % (IP_ENDPOINT,
urllib.urlencode({'username': ip_usr, 'password': ip_pwd})))
count = 0
for bm in bookmarks.values():
ip_query = urllib.urlencode({'url':bm['url'],'title':bm['title'].encode('utf-8'), 'username':ip_usr, 'password':ip_pwd})
ip_url = '%s/add?%s' %(IP_ENDPOINT, ip_query)
open_url(ip_url)
count += 1
print ''''%s' copied successfully''' %bm['title']
print '%d bookmarks copied' %count
if __name__ == "__main__":
import sys
apply(main, sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment