http://qs321.pair.com?node_id=441274

Powerful Monks, please forgive me because I've committed a sin. After few days inside this community, I've had the arrogance to elevate myself to the level of gods and create a Monk from /dev/null...

It actually taught me to use WWW::Mechanize, which I find quite useful! Here's the code for the virtual monk:

#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use HTTP::Response; my ($user, $passwd) = ("anotherTime", "no_abuse_please"); my $homepage = 'http://www.perlmonks.org/'; print STDERR "getting homepage [$homepage]\n"; my $mech = WWW::Mechanize->new( agent => 'Virtual Monk 0.1' ); $mech->get($homepage)->is_success() || die "unable to get $homepage, s +topped"; print STDERR "logging in\n"; $mech->submit_form( form_name => 'login', fields => { user => $user, passwd => $passwd }, button => 'login' )->is_success() || die "unable to log in $homepage, stopped"; # Ensure we've logged in successfully my $logout = $mech->find_link( text => "log $user out" ); die "did not log in, stopped" unless $logout; my $votes = 0; for (my $maxcount = 0; $maxcount < 100; ++$maxcount) { print STDERR "going in my home node\n"; $mech->follow_link( text => $user )->is_success() || die "could not get into my home node, stopped"; print STDERR "assessing if I've spare votes\n"; last unless $mech->response()->content() =~ /You have <b>([0-9]+)< +\/b> votes? left today\./; last unless $1; # Find a page where I can vote. Index indicates the index of the v +oting form my $index = 0; for (my $maxcount2 = 0; $maxcount2 < 100 && ! $index; ++$maxcount2 +) { print STDERR "getting a random page\n"; $mech->follow_link( text => 'Random Node' )->is_success() || die "could not get a random node, stopped"; print STDERR "verifying I can vote anywhere in it\n"; my $count = 0; foreach my $form ($mech->forms()) { ++$count; # Form numbers start from 1 if (defined($form->find_input('sexisgreat', 'submit'))) { $index = $count; last; } } } if ($index) { # A voting form is available print STDERR "casting a vote\n"; $mech->form_number($index); $mech->set_visible( [ radio => "1" ] ); $mech->click('sexisgreat'); ++$votes; } } print STDERR "$votes vote" . ($votes != 1 ? "s" : "") . " cast\n"; # Log out print STDERR "logging out\n"; $mech->get($logout->url()) || die "unable to log out, stopped";
The virtual monk in the configuration is a registered account... forgive me for this as well. Being an acolyte, I think it should be expected some - ehr - inclination to break rules..

The virtual monk isn't running in a cron job, tough. No, it's not running with my account as well :) I'm only wondering how much time it would require him to become saint - I'll evaluate this and post here if some god doesn't kick me out!

Flavio.

-- Don't fool yourself.