Created
October 28, 2012 12:33
-
-
Save straup/3968495 to your computer and use it in GitHub Desktop.
Use WWW::Mechanize to post notes to pinboard.in
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 strict; | |
use WWW::Mechanize; | |
{ | |
&main(); | |
exit; | |
} | |
sub main { | |
# This part is left as an exercise to the reader. | |
# You can hardcode these or use Getopt::Something | |
# or Config::Simple or some combination of them | |
# all... | |
my $username = ''; | |
my $password = ''; | |
my $title = ''; | |
my $tags = ''; | |
my $note = ''; | |
my $public = 0; | |
# Go! | |
my $action = ($public) ? 'save_public' : 'save_private'; | |
my $button = ($public) ? 'save public' : 'save private'; | |
# Yes, that's right – it's necessary or LWP::UA | |
# will freak out and die | |
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0; | |
my $m = WWW::Mechanize->new(); | |
$m->get("https://pinboard.in/"); | |
$m->field('username', $username); | |
$m->field('password', $password); | |
$m->submit(); | |
# There's actually not much in the way of error checking | |
# the login but at least we can see if the server freaks | |
# out | |
if ($m->status != 200){ | |
warn "failed to log in: " . $m->message; | |
return 0; | |
} | |
# Now add the note - see also: | |
# http://search.cpan.org/~jesse/WWW-Mechanize/lib/WWW/Mechanize/FAQ.pod#I_submitted_a_form,_but_the_server_ignored_everything!_I_got_an_empty_form_back! | |
$m->get("https://pinboard.in/note/add/"); | |
$m->field('title', $title); | |
$m->field('tags', $tags); | |
$m->field('note', $note); | |
$m->field('action', $action); | |
$m->click_button('value', $button); | |
if ($m->status != 200){ | |
warn "failed to post note: " . $m->message; | |
return 0; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment