Skip to content

Instantly share code, notes, and snippets.

@throughnothing
Created April 26, 2011 00:52
Show Gist options
  • Save throughnothing/941581 to your computer and use it in GitHub Desktop.
Save throughnothing/941581 to your computer and use it in GitHub Desktop.
script to download instapaper feed in epub format
#!/usr/bin/env perl
use v5.10;
use DateTime;
use HTTP::Request;
use LWP::UserAgent;
use HTTP::Cookies;
my $user = '';
my $pass = '';
my $now = DateTime->now;
my ($y, $m, $d) = ($now->year, $now->month, $now->day);
my $filename = "Instapaper-$m-$d-$y.epub";
my $file = "$ENV{HOME}/Downloads/$file";
if(-d '/Volumes/NOOK/My Files/Documents'){
# Nook stuff
$file = "/Volumes/NOOK/My Files/Books/$filename";
}
my $ua = LWP::UserAgent->new(cookie_jar =>
HTTP::Cookies->new(file => "/tmp/cookies.txt", autosave => 1));
my $req = HTTP::Request->new( POST => 'https://www.instapaper.com/user/login',
[ 'Content-Type' => 'application/x-www-form-urlencoded' ],
'username=' . $user . '&password=' . $pass);
# Log In
my $res = $ua->request($req);
$res->content =~ m/Logging in/g ?
say 'Logged in' : ( say 'Couldn\'t Log In' and exit );
say "Downloading epub to $file...";
my $epub = $ua->request(
HTTP::Request->new(GET => 'https://www.instapaper.com/epub')
);
open my $fh, '>', $file;
print $fh $epub->content;
# Remove cookies
unlink('/tmp/cookies.txt');
@caifara
Copy link

caifara commented Mar 3, 2012

Thank you very much for the script. I used it to put together a simple script to load the epub into my kobo (unwired actually):

https://github.com/caifara/Instapaper2Kobo

@throughnothing
Copy link
Author

Awesome, I'm glad this was useful for you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment