Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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 => ''; $| = 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


In reply to Re: hup - home node updater (with scratchpad ability) by thatguy
in thread hup - home node updater by ar0n

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2017-05-22 19:35 GMT
    Find Nodes?
      Voting Booth?