Skip to content

Instantly share code, notes, and snippets.

@Schnouki
Created November 26, 2010 14:54
Show Gist options
  • Save Schnouki/716807 to your computer and use it in GitHub Desktop.
Save Schnouki/716807 to your computer and use it in GitHub Desktop.
Copy data from a "Read it later" account to an "Instapaper" account
import urllib
import urllib2
import simplejson as json
API_KEY = '37dp9fcqA1299u9aK7gc2c2C84ddnd78'
API_ROOT = 'https://readitlaterlist.com/v2/'
class RILError(Exception):
pass
class RIL(object):
def __init__(self, username, password):
self.username = username
self.password = password
if not self.auth():
raise RILError("Invalid login")
def _query(self, method, **kwds):
kwds["apikey"] = API_KEY
kwds["username"] = self.username
kwds["password"] = self.password
params = urllib.urlencode(kwds)
url = "%s%s?%s" % (API_ROOT, method, params)
try:
u = urllib2.urlopen(url)
return u.getcode(), u.read()
except urllib2.HTTPError, e:
return e.getcode(), e.read()
def auth(self):
code, data = self._query("auth")
return code == 200
def get(self, **kwds):
kwds["format"] = "json"
code, data = self._query("get", **kwds)
assert code == 200
return json.loads(data, "latin-1")
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# This is a simple tool to export data from Read it later to Instapaper.
# Just download instapaperlib (frop PyPI), ril.py (here), edit this file with your
# own usernames and passwords, and you're good to go.
# Warning: this tool is *very* dubm, use it at your own risks! ;)
import instapaperlib # Available on PyPI
import ril # Available in this Gist :)
import sys
r = ril.RIL(RIL_USERNAME, RIL_PASSWORD)
ip = instapaperlib.Instapaper(IP_USERNAME, IP_PASSWORD)
assert ip.auth()[0] == 200
src = r.get()
assert src["status"] == 1
keys = src["list"].keys()
keys.sort(key=int)
tot = len(keys)
for n in xrange(tot):
item = src["list"][keys[n]]
sys.stdout.write("\r\033[0K[%d/%d] %s" % (n+1, tot, item["title"].encode("utf-8")))
sys.stdout.flush()
code, msg = ip.add_item(item["url"], item["title"].encode("utf-8"))
if code != 201:
print "\nError: %s" % msg
sys.exit(1)
print "\n%d items added" % len(src["list"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment