http://qs1969.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.

Replies are listed 'Best First'.
Re: Confessions of a virtual monk
by ysth (Canon) on Mar 21, 2005 at 20:11 UTC
      Wow, maybe I put too few smileys in my post to make it clear it was a joke. I wanted to learn something about WWW::Mechanize, and I did it with fun working on perlmonks itself. I've learned more in a few days here than in many months, and I really thought that PerlMonks was a funny place where you could learn Perl enjoing it.

      As a matter of fact, I'm nearly proud of negative votes. On one hand, it's sad for me that my post wasn't taken as it is (and, as a matter of fact, I DO NOT use a bot for my PM experience); on the other, I thought it really was a Cool Use For Perl and I'm happy to have posted it. I still think that the fact that I've talked about this CUFP should be a clue of the fact that I like *doing* Perl and *sharing* my experience on WWW::Mechanize more than just setting up a bot, but I also understand that humour is not perceived in the same way as me by other people, in particular when many different (and surely respectable) cultures are involved. The only thing I can say is "sorry", if I've offended anyone, which I hope is not the case.

      Please be free to track my account (you can see the IPs from which I connect) to see my previous days of activity and the ones to come. You'll find that I enjoy posting as much as voting, which is something that a bot would make with some difficulty.

      As to reporting to gods of the multiple account, I was sure that the joke itself would be sufficient - do you know a more direct way? Anyway, thank you for not just droppin' a "--" without explanation: at least, I've learnt something about how to behave in the future within this community.

      Flavio.

      -- Don't fool yourself.
        You can contact the gods by /msg gods ... in the chatterbox. I mostly posted to warn others who might be tempted to try your code. Don't worry about the downvotes, I've had much worse (including the simulation node I posted a link to, which initially was treated as an attack on how the monastery works).
Re: Confessions of a virtual monk
by 2mths (Beadle) on May 05, 2005 at 13:30 UTC
    I'd like to say Thankyou! for this post and example script. It's cast light on an area\use of perl that I've been stuck for years with. I've only tested the basics but I'm sure with this example and the testing I've done I can no go on to do more. (++ from me)

    Note: I realise that what was done was against the rules and perhaps that can never be right but I'm glad it was done and posted.
      Please understand it is a joke, even if it's a working one. If it helps you shed a light over WWW::Mechanize it's good and I'm happy with that, if it helps you cheat with PM it's not good (and I admit to feel a bit unhappy, too).

      I personally enjoy voting intelligently*, and sometimes I end up with unused votes just because I don't find the necessary number of posts deserving them - and this at the cost of not earning the 1/4-probable XPs.

      *In the sense that I like to use my intelligence to vote. I obviously don't mean that my votes are objectively intelligent :)

      Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

      Don't fool yourself.
        I took it as a serious post - but with a humerous example provided. (Very comprehensive and useful example).

        I'm not after it for XP. It's of interest to me because although my skills are limited - I like doing things in Perl (even if they don't have much use) and because the web and web related stuff is such a big part life nowadays.

        What I intend using if for first is to try to use it to connect to network devices (printers and the like) to query them for their status, toner levels etc.
        I had managed to use something around LWP to read a single page. But I couldn't work out\do form submission or following links. I'm now hoping I might be able to 'read' DHTML pages (the world moves on and I'm a looong way behind). The next challege is HTTPS (really stumped there) as even though they are just friggin' printers the world has gone security mad!

        Thanks again for your efforts and bravery in doing\posting.