#!/usr/bin/perl
use strict;
use Data::Dumper;
use LWP;
use LWP::UserAgent;
my $money_url = 'http://www.alphabounce.com/forum/thread/6639?;page=';
my $missile_url = 'http://www.alphabounce.com/forum/thread/2833?;page=';
sub getForumContent($)
{
my $content;
my $ua = new LWP::UserAgent;
# Various enhancement possibilities:
$ua->max_size(200000); # 200k byte limit
$ua->timeout(10); # 10 sec timeout is default
$ua->agent("Mozilla/6.0"); # Or something equally mysterious
my $req = new HTTP::Request GET => $_[0];
my $res = $ua->request($req);
if ($res->is_success)
{
$content = $res->content;
}
else
{
die "Could not get content";
exit;
}
$content =~ m/
([^<>]+)|im) { $date = $1; }
if (m|"/user/([0-9]+)">([^<>]+)|im) { $userid = $1; $username = $2; }
if (m|"content">([^<>]+)|im) { $content = $1 . $'; }
if ($content =~ m||im) { $content = $`; }
if (m|class="coord"[^>]*>([\[\]\)\(,;]*)([^<>]+)([\[\]\)\(,;]*)|im)
{
@coord = split /[\[\]\)\(,;]+/, $2;
#print Dumper \@coord;
}
#[45][-2]
#print "{$date}{$userid}{$username}{$coord[0],$coord[1]}{$content}\n";
my @a = split(/\s*
\s*/i, $content);
foreach my $row (@a)
{
$row =~ s/^\s+//gm;
$row =~ s/\s+$//gm;
$row =~ s/Salut,\s*//gmi;
$row =~ s/Merci,?\s*//gmi;
$row =~ s/(Le\s*)?message(\s*est\s*)?trop\s+court ?!?//gmi;
$row =~ s/youp+is?//gmi;
$row =~ s/\W+gr+\.*\s+/ /gmi;
$row =~ s/\.+\s*/ /gmi;
$row =~ s|\s+| |gmi;
$row =~ s|?strong>||gmi;
$row =~ s|?cite>||gmi;
$row =~ s|?b>||gmi;
$row =~ s|?u>||gmi;
$row =~ s|?i>||gmi;
$row =~ s|?em>||gmi;
$row =~ s|?p>||gmi;
$row =~ s|]+>[^<>]+||gmi;
$row =~ s|\W+([ou]ne?)\W+| 1 |gmi;
$row =~ s|\W+(twos*)\W+| 2 |gmi;
$row =~ s|\W+(deux*)\W+| 2 |gmi;
$row =~ s|\W+(trois)\W+| 3 |gmi;
$row =~ s|\W+(three*s*)\W+| 3 |gmi;
$row =~ s|\W+(quatre*s*)\W+| 4 |gmi;
$row =~ s|\W+(four*s*)\W+| 4 |gmi;
$row =~ s|\W+(cinqe*s*)\W+| 5 |gmi;
$row =~ s|\W+(five*s*)\W+| 5 |gmi;
$row =~ s|\W+(sixe*s*)\W+| 6 |gmi;
$row =~ s|\W+(septe*s*)\W+| 7 |gmi;
$row =~ s|\W+(seve*n*s*)\W+| 7 |gmi;
$row =~ s|\W+(huite*s*)\W+| 8 |gmi;
$row =~ s|\W+(ei[gh]+t*s*)\W+| 8 |gmi;
$row =~ s|\W+(neuf*s*)\W+| 9 |gmi;
$row =~ s|\W+(nine*s*)\W+| 9 |gmi;
$row =~ s|\W+(dizaine*s*)\W+| 10 |gmi;
$row =~ s|\W+(dize*n*s*)\W+| 10 |gmi;
$row =~ s|\W+(eleve*n*s*)\W+| 11 |gmi;
$row =~ s|\W+(onze*n*s*)\W+| 11 |gmi;
$row =~ s|\W+(douzaine*s*)\W+| 12 |gmi;
$row =~ s|\W+(doze*n*s)\W+| 12 |gmi;
if ($row)
{
$row =~ s|| $2|gmi;
$row =~ s|à|a|gmi;
$row =~ s|À|a|gmi;
$row =~ s|â|a|gmi;
$row =~ s|ä|a|gmi;
$row =~ s|é|e|gmi;
$row =~ s|ê|e|gmi;
$row =~ s|è|e|gmi;
$row =~ s|ë|e|gmi;
$row =~ s|ç|c|gmi;
$row =~ s|Ç|c|gmi;
$row =~ s|ù|u|gmi;
$row =~ s|ï|i|gmi;
$row =~ s|ô|o|gmi;
$row =~ s|\s*miner\w*\s*| \$ |gmi;
$row =~ s|\s*rubi\w*\s*| \$ |gmi;
$row =~ s|\s*(>)+\s*| = |gmi;
my $ref = parseContent($row, $coord[0], $coord[1]);
if ($ref)
{
my ($x,$y,$total2,$red,$blue,$green) = @{ $ref };
print "\n($x,$y,$total2,$red,$blue,$green)\n\n";
if ($total2 >= 0)
{
my $text = sprintf("[%3d,%3d, '%3d, ", $coord[0],$coord[1], $total2);
if ($red >= 0)
{
$text .= ", $red reds";
}
if ($blue >= 0)
{
$text .= ", $blue blues";
}
if ($green >= 0)
{
$text .= ", $green greens";
}
$text .= "'], # '$date', '$userid', '$username' \n";
$text =~ s/,+\s*,+/,/gmi;
print $text;
}
}
}
}
#print "{$_}\n";
}
}
}
sub getInt($)
{
$_[0] =~ m/([0-9]+)/m;
return $1;
}
sub parseContent($$$)
{
my ($content, $x, $y) = @_;
my $total = -1;
my $red = -1;
my $blue = -1;
my $green = -1;
#print "[$x,$y]: {$content} =>";
if ($content =~ m|([\[\]\)\(,;]*)([^<>]+)([\[\]\)\(,;]*)|im)
{
if ($content =~ m/(((my)|(mon)|(ma))\s*((positions*)|(emplacements*)))|(ou\s*je\s*suis)|(ici)/im)
{
# Sur ma position
#print "\nFound: My Position [$x,$y]\n";
}
else
{
if ($content =~ m/[\[\/\\\\,;\(\)\]\s*]*([0-9\-\+\.]+)[\[\/\\\\,;\(\)\]\s]+([0-9\-\+\.]+)[\[\/\\\\,;\(\)\]\s]*/mi)
{
$x = $1;
$y = $2;
#print "\nFound [$x,$y]\n";
}
else
{
#print "\nNot found !\n";
}
}
if ($content =~ m/([0-9]+)\s*\$/mi)
{
$total = getInt($&);
}
print "[$x,$y]:[$content]";
if ($content =~ m/\s*([0-9]+)\s*(\s*briq*u*c*k*e*s*\s*)?((verte*s*)|(greene*s*))(\s*briq*u*c*k*e*s*\s*)?\s*/mi)
{
$green = getInt($&);
print "[$green]";
}
elsif ($content =~ m/\s*(\s*briq*u*c*k*e*s*\s*)?((verte*s*)|(greene*s*))(\s*briq*u*c*k*e*s*\s*)?\s*([0-9]+)\s*/mi)
{
$green = getInt($&);
}
if ($content =~ m/\s*([0-9]+)\s*(\s*briq*u*c*k*e*s*\s*)?((bleue*s*)|(blue*s*))(\s*briq*u*c*k*e*s*\s*)?\s*/mi)
{
$blue = getInt($&);
}
elsif ($content =~ m/\s*(\s*briq*u*c*k*e*s*\s*)?((bleue*s*)|(blue*s*))(\s*briq*u*c*k*e*s*\s*)?\s*([0-9]+)\s*/mi)
{
$blue = getInt($&);
}
if ($content =~ m/\s*([0-9]+)\s*(\s*briq*u*c*k*e*s*\s*)?((rouge*s*)|(rede*s*)|(rose*s*))(\s*briq*u*c*k*e*s*\s*)?\s*/mi)
{
$red = getInt($&);
}
elsif ($content =~ m/\s*(\s*briq*u*c*k*e*s*\s*)?((rouge*s*)|(rede*s*)|(rose*s*))(\s*briq*u*c*k*e*s*\s*)?\s*([0-9]+)\s*/mi)
{
$red = getInt($&);
}
print "[$x,$y]= T[$total] R[$red] G[$green] B[$blue] => [$content]\n";
}
else
{
#print "!!\n"
}
if ($total < 0)
{
$total = 0;
if ($red > 0) { $total += (25 * $red); }
if ($blue > 0) { $total += ( 5 * $blue); }
if ($green > 0) { $total += ( 1 * $green); }
if ($red < 0 && $blue < 0 && $green < 0) { $total = -1; }
}
else
{
#if ($red < 0 && $blue < 0 && $green < 0) { $green = $total; }
}
my @data = ($x,$y,$total,$red,$blue,$green);
return \@data;
}
for my $n (21..21)
{
my $content = getForumContent($money_url .$n);
print "# Page $n\n";
parseForumMessage($content);
if ($content !~ m|"next"\s*>Next<|mi) { last; }
#print $content;
#exit;
}
#print $content;