Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of IlyaM (2933)

Monday December 01, 2003
10:30 AM

Yet another go addict

[ #16096 ]

If you never played go do not click this link, you still can be saved from this drug :)

Just hacked this simple script to poll for my turns to move on http://www.dragongoserver.net/. To my taste the script is a bit ugly but it works.

#!/usr/bin/perl

use strict;
use warnings;

my $go = DragonGoServer->new;

$go->login($ENV{DRAGONGO_LOGIN}, $ENV{DRAGONGO_PASSWORD});

while(1) {
    $go->read_status;
    sleep 480;
}

package DragonGoServer;

use base qw(WWW::Mechanize);

sub redirect_ok { 1 }

sub login {
    my $self = shift;
    my ($login, $password) = @_;

    $self->get('http://www.dragongoserver.net/');
    $self->submit_form(form_name => 'loginform',
                       fields    => { userid => $login,
                                      passwd => $password });
}

sub read_status {
    my $self = shift;

    $self->get('http://www.dragongoserver.net/status.php');

    if($self->content =~ /Your turn to move in the following games/) {
        print "Your turn to move in the following games:\n";

        my $re = qr!game\.php\?gid= (\d+)
                    .*?
                    userinfo\.php\?uid=\d+ .*? <font.*?> (.*?) </font>
                   !x;

        my $content = $self->content;

        while($content =~ /\G[\s\S]*?$re/g) {
            print "Game #$1, player '$2'\n";
        }

        print "\n"
    }
}

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.