Simply set the $user
and pass
variables, then run instapaper.pl
when your Nook is plugged in and it will automatically download your instapaper feed to your nook.
Created
October 28, 2011 23:11
-
-
Save throughnothing/1323814 to your computer and use it in GitHub Desktop.
Get epub from instapaper, lwp version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment