]> ruin.nu Git - ndwebbie.git/blobdiff - scripts/stats.pl
Use new race infrastructure for members stats
[ndwebbie.git] / scripts / stats.pl
index 3d4222e13ea300a6bc13a0c295d2e37c47d42d0f..ee12e933e2a4af0968638762127ce1086c887529 100755 (executable)
@@ -24,32 +24,40 @@ use strict;
 use warnings;
 use DBI;
 use DBD::Pg qw(:pg_types);
+use Data::Dumper;
 
-use LWP::Simple;
-
-$0 =~ /(.*\/)[^\/]/;
-my $dir = $1;
-our $dbh;
-for my $file ("/home/whale/db.pl")
-{
-       unless (my $return = do $file){
-               warn "couldn't parse $file: $@" if $@;
-               warn "couldn't do $file: $!"    unless defined $return;
-               warn "couldn't run $file"       unless $return;
-       }
-}
-$dbh->do("SET CLIENT_ENCODING TO 'LATIN1';");
+use LWP::Simple qw/get $ua/;
+$ua->agent("Stupid user agent check is stupid");
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+use ND::DB;
+use NDWeb::Stats;
+
+our $dbh = ND::DB::DB();
 
-my $file = get("http://game.planetarion.com/manual.php?page=stats");
+my $file = get("http://game.planetarion.com/manual.pl?action=statsxml");
 $dbh->begin_work;
-my $st = $dbh->prepare(q{INSERT INTO ship_stats (name,"class",target,"type",init,guns,armor,damage,eres,metal,crystal,eonium,race) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)});
-while ($file =~ /((?:\w| )+)<\/td><td>(\w+)<\/td><td>(\w+)<\/td><td>(\w+)\D+(\d+)\D+(\d+)\D+(\d+)\D+?(\d+|-)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+\d+\D+\d+.+?(\w+)<\/td>/g){
-       my $dmg = $8;
-       $dmg = 0 if $dmg eq '-';
-       $st->execute($1,$2,$3,$4,$5,$6,$7,$dmg,$9,$10,$11,$12,$13) or die $dbh->errstr;
-       #print "$1,$2,$3,$4,$5,$6,$7,$dmg,$9,$10,$11,$12,$13\n";
+my $st = $dbh->prepare(q{
+INSERT INTO ship_stats
+       (ship,"class",t1,t2,t3,"type",init,guns,armor,damage,eres,metal,crystal,eonium,race, cloaked, baseeta)
+       VALUES(?,?,NULLIF(?,'-'),NULLIF(?,'-'),NULLIF(?,'-'),?,?,?,?,?,?,?,?,?,(SELECT race FROM races WHERE race_name = ?), ?, ?)});
+
+my @columns = qw/ship class t1 t2 t3 type init guns armor damage eres metal crystal eonium race cloaked baseeta/;
+
+my @ships = parseStats($file);
+for my $ship (@ships) {
+       my @data;
+       for my $c (@columns) {
+               push @data, $ship->{$c};
+       }
+       #print Dumper(\@data), "\n";
+       print "@data\n";
+       $st->execute(@data) or die $dbh->errstr;
 }
 
+
 $dbh->commit;
 
 $dbh->disconnect;