Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; use Term::ReadPassword; 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); 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, "contentofpad=s"=> \$scratchfile, "makepublic" => \$setpublic, "significant" => \$significant, "verbose" => \$verbose ); unless ( defined $username ) { $username = ""; until ( $username =~ /\S/ ) { print "Username: "; chomp($username = <STDIN>); } } unless ( defined $password ) { $password = ""; until ( $password =~ /\S/ ) { $password = read_password("Password: ") } } die usage() unless $username && $password;; die "Can't find $file\n" if defined $file and not -f $file; $homenode = join "", do { local @ARGV = $file; <> } if defined $fi +le; die "Can't find $scratchfile\n" if defined $scratchfile and not -f $scratchfile; $scratchpad = join "", do { local @ARGV = $scratchfile; <> } if de +fined $scratchfile; die "Can't find image $image\n" if defined $image and not -f $image; $ua = new LWP::UserAgent( agent => "Homenode Updater" ); $ua->cookie_jar( HTTP::Cookies->new() ); print "Logging in... " if $verbose; die "Couldn't log in. Is your username/password right?\n" unless $ua->request( POST PM, [ node_id => TINYNODE, op => 'login', user => $username, passwd => $password ] )->as_string() =~ /userpass/; print "done.\n" if $verbose; print "Fetching... " if $verbose; my $html = $ua->request( POST PM, [ displaytype => "edit", node => $username ] )->content(); print "done.\n" if $verbose; print "Parsing... " if $verbose; my %default = parse($html); print "done.\n" if $verbose; print "Updating... " if $verbose; my $content = [ displaytype => "edit", node => $username, user_realname => $realname || $default{user_realname} | +| "", user_passwd1 => $password, user_passwd2 => $password, user_email => $email || $default{user_email} || "", user_doctext => (defined $homenode ? $homenode : $defa +ult{user_doctext}) || "", user_scratchpad => (defined $scratchpad ? $scratchpad : $ +default{user_scratchpad}) || "", setscratchpublic => ($setpublic ? "on" : $default{setscrat +chpublic}) || "", setsetting_location => $location || $default{setsetting_locat +ion} || "", significantupdate => $significant ? "on" : "", sexisgood => "stumbit" ]; push @$content, imgsrc_file => [$image] if defined $image; $ua->request( POST PM, Content_Type => 'form-data', Content => $content ); 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 Make scratchpad public -n <string> Your real name -e <string> Your email address -l <string> Your 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_passwd2 +setsetting_location ); my $p = new HTML::TokeParser ( \$html ); while ( my $token = $p->get_tag("textarea") ) { $default{user_doctext} = $p->get_text if $token->[1]{name} eq "use +r_doctext"; $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; $default{setscratchpublic} = "on" if $token->[1]{name} eq 'setscra +tchpublic' && $token->[1]{checked}; } return %default; }

In reply to hup - home node updater by ar0n

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (7)
    As of 2014-08-28 01:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (254 votes), past polls