Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: hup - home node updater (with scratchpad ability)

by thatguy (Parson)
on Sep 20, 2001 at 21:59 UTC ( [id://113654]=note: print w/replies, xml ) Need Help??


in reply to hup - home node updater

Since I use it so much, I thought I would add scratchpad capability.

added options [ -c | --contentsofpad ] and [ -m | --makepublic ]

#!/usr/bin/perl use strict; use HTTP::Request::Common 'POST'; use HTTP::Cookies; use LWP::UserAgent; use HTML::TokeParser; use Getopt::Long; use constant TINYNODE => 16046; use constant PM => 'http://www.perlmonks.org/index.pl'; $| = 1; { my ($ua, $req); my ($homenode, $username, $password, $file); my ($realname, $email, $image, $location); my ($verbose, $significant); # added for scratchpad my ($setpublic,$scratchfile,$scratchpad); GetOptions( "username=s" => \$username, "password=s" => \$password, "name=s" => \$realname, "email=s" => \$email, "image=s" => \$image, "location=s" => \$location, "homenode=s" => \$file, # added for scratchpad "contentofpad=s"=> \$scratchfile, "makepublic" => \$setpublic, "significant" => \$significant, "verbose" => \$verbose ); die usage() unless $username && $password; die "Can't find $file\n" if defined $file and not -f $file; # added for scratchpad die "Can't find $scratchfile\n" if defined $scratchfile and not -f + $scratchfile; # added for scratchpad $scratchpad = join "", do { local @ARGV = $scratchfile; <> } if de +fined $scratchfile; $homenode = join "", do { local @ARGV = $file; <> } if defined $fi +le; die "Can't find image $image\n" if defined $image and not -f $imag +e; $ua = new LWP::UserAgent("Homenode Updater"); $ua->cookie_jar( HTTP::Cookies->new() ); print "Logging in...\n" if $verbose; $req = POST PM, [ node_id => TINYNODE, op => 'login', user => $username, passwd => $password ]; die "Couldn't log in. Is your username/password right? $!\n" unless $ua->request($req)->as_string() =~ /userpass/; print "done.\n" if $verbose; $req = POST PM, [ displaytype => "edit", node => $username ]; my $html = $ua->request($req)->content(); print "Parsing... " if $verbose; my %default = parse($html); print "done.\n" if $verbose; print "Updating... " if $verbose; $req = POST PM, Content_Type => 'form-data', Content => [ displaytype => "edit", node => $username, imgsrc_file => $image ? [$image] : "", user_realname => $realname || $default{user_realn +ame}, user_passwd1 => $password, user_passwd2 => $password, user_email => $email || $default{user_email}, user_doctext => defined $homenode ? $homenode : +$default{user_doctext}, # added for scratchpad user_scratchpad => defined $scratchpad ? $scratc +hpad : $default{user_scratchpad}, setscratchpublic => $setpublic ? "on" : "", setsetting_location => $location || $default{setsetting +_location}, significantupdate => $significant ? "on" : "", sexisgood => "stumbit" ]; $ua->request($req); print "done.\n" if $verbose; } sub usage { return <<"EOT"; Usage: $0 -u username -p password [ options ] Options: -i <file> Home node picture -h <file> File containing home node contents -c <file> File containing scratchpad contents -m Set Scratchpad public -n <string> Your real name -e <string> Your email address -l <string> Location -s Significant update -v Be a little verbose EOT } sub parse { my $html = shift; my %default; my @params = qw( user_realname user_email user_passwd1 user_passwd +2 setsetting_location ); my $p = new HTML::TokeParser ( \$html ); if ( my $token = $p->get_tag("textarea") ) { $default{user_doctext} = $p->get_text if $token->[1]{name} eq +"user_doctext"; # added for scratchpad $default{user_scratchpad} = $p->get_text if $token->[1]{name} +eq "user_scratchpad"; } while ( my $token = $p->get_tag("input") ) { next unless exists $token->[1]{name}; $default{ $token->[1]{name} } = $token->[1]{value} if grep { $ +_ eq $token->[1]{name} } @params; } return %default; } =head1 NAME hup =head1 DESCRIPTION hup is a simple tool to update your home node. It's basically a command-line interface to the "Edit your user information" link on one's homenode. hup allows you to change anything on that page, except the password. You can use the following switches (of which -u and -p are mandatory): =over 4 =item C<-u> or C<--username> Your Perl Monks username =item C<-p> or C<--password> Your Perl Monks password =item C<-i> or C<--image> The location of your home node picture =item C<-h> or C<--homenode> The location of the file containing home node contents =item C<-n> or C<--name> Your real name =item C<-e> or C<--email> Your email address =item C<-c> or C<--contentofpad> The location of the file containing scratch pad contents =item C<-m> or C<--makepublic> Make scratchpad public =item C<-l> or C<--location> Your Location =item C<-s> or C<--significant> Use this switch to flag it as a significant update =item C<-v> or C<--verbose> Be a little verbose =back =head1 EXAMPLES Update your home node picture: hup -u mynick -p mypassword -i /path/to/image.jpg Update your homenode contents and location and flag it as a significan +t update, and be verbose: hup -u mynick -p mypassword -h /etc/passwd -l "Foo Bar" -s -v =cut

-p

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://113654]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-18 04:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found