X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=scripts%2Fstats.pl;h=ee12e933e2a4af0968638762127ce1086c887529;hb=HEAD;hp=3d4222e13ea300a6bc13a0c295d2e37c47d42d0f;hpb=c643b311c8f134a59625192b900aa28b3f12d4f1;p=ndwebbie.git diff --git a/scripts/stats.pl b/scripts/stats.pl index 3d4222e..ee12e93 100755 --- a/scripts/stats.pl +++ b/scripts/stats.pl @@ -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>(\w+)<\/td>(\w+)<\/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;