#!/usr/bin/perl
use strict;
use warnings;
use HTML::TableContentParser;
use Time::Local;
use WWW::Mechanize;
use constant ID => 1;
use constant CREATE => 3;
use constant STATS => 4;
use constant LAST => 4;
use constant EXP => 5;
use constant LENGTH => 11;
# length && ( rep || create && last )
my %opt = (
length => 500,
exp => 200,
create => 365,
last => 45,
url => 'http://tinymicros.com/pm/index.php?goto=monkstats&sortopt=15&sortlist=15,1,3&',
pos => 0,
);
my $finished;
my $mech = WWW::Mechanize->new( autocheck => 1 );
my @homenodes;
while ( ! $finished ) {
$mech->get( $opt{url} . '&start=' . $opt{pos} );
my $table = HTML::TableContentParser->new()->parse( $mech->content() );
for my $row ( @{ $table->[ STATS ]{rows} } ) {
my $length = Get_Length( $row );
next if ! defined $length;
if ( $length < $opt{length} ) {
$finished = 1;
last;
}
my $id = Get_ID( $row );
push @homenodes , $id if defined $id;
}
$opt{pos} += 50;
}
sub Get_Length {
my $row = shift;
my $data = ${ $row->{cells} }[ LENGTH ]{data};
($data) = $data =~ /(\d+)/ if defined $data;
return $data;
}
sub Get_ID {
my $row = shift;
my ($id) = ${ $row->{cells} }[ ID ]{data} =~ /(\d+)/;
my ($exp) = ${ $row->{cells} }[ EXP ]{data} =~ /(\d+)/;
return $id if $exp >= $opt{exp};
my $create = Get_Days( ${ $row->{cells} }[ CREATE ]{data} );
my $last = Get_Days( ${ $row->{cells} }[ LAST ]{data} );
return $create >= $opt{create} && $last <= $opt{last} ? $id : undef;
}
sub Get_Days {
my $then = shift;
($then) = $then =~ m|