View Single Post
Old 04-14-2011, 10:56 PM   #3
banjopicker
Member
banjopicker began at the beginning.
 
banjopicker's Avatar
 
Posts: 24
Karma: 10
Join Date: May 2007
Device: PRS-505
The following is a python script I wrote to download instapaper articles with the Calibre recipe, save them as an epub, and then archive all instapaper articles so that it won't keep re-downloading the same ones.

There is probably a simpler way to do this, but I am a Python novice, and learned just enough to get it to work.

You will need to have urllib and urllib2 libraries installed in Python for this to work. You will also need to change the username/password and form_key fields to your own. I also have the windows path to Calibre hard-coded in the script--change it if Calibre is in a different directory for you.

Code:
import datetime, subprocess
from urllib import urlencode
import urllib2

myUsername = "youremail@yourprovidor.com" 
myPassword = "yourpass"
myForm_Key = "8IL7UWrLhP3l2fmD2SZg" #Unique value probably linked to username/pass -- you must change this

#You get myForm_Key by logging in to Instapaper one time, looking at the 
#source of the HTML page, finding the form_key value, and pasting it here.
#Maybe if people find this script useful I will have it automate the task.

#construct a windows command-line command to use Calibre with Instapaper
todayDate = datetime.date.today().isoformat()
myFilename = 'Instapaper ' + todayDate + '.epub'
params2 = urlencode(dict(form_key=myForm_Key, submit="Archive All"))
mySystemCommand = 'C:\Program Files\calibre2\ebook-convert Instapaper.com.recipe "' + myFilename + '" --username ' + myUsername + ' --password ' + myPassword

#execute Calibre command
ret = subprocess.call(mySystemCommand)

#login to Instapaper so that downloaded archives can now be archived
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
urllib2.install_opener(opener)

params = urlencode(dict(username=myUsername, password=myPassword))
f = opener.open('http://www.instapaper.com/user/login', params)
data = f.read()
f.close()

#archive all articles in unread folder
f=opener.open("http://www.instapaper.com/bulk-archive", params2)
data2=f.read()
f.close()
banjopicker is offline   Reply With Quote