X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=scripts%2Fstats.pl;h=6e9c8508e2332ca393162e366cc6b0392f781c5b;hb=c00d916b84908f24522800479b669014856354df;hp=5b7d6a2136546054ccab6e3c53dc6cc6ecd98310;hpb=fda0878e43c647c3fbaba000b66a0780ac7450f4;p=ndwebbie.git diff --git a/scripts/stats.pl b/scripts/stats.pl index 5b7d6a2..6e9c850 100755 --- a/scripts/stats.pl +++ b/scripts/stats.pl @@ -25,7 +25,8 @@ use warnings; use DBI; use DBD::Pg qw(:pg_types); -use LWP::Simple; +use LWP::Simple qw/get $ua/; +$ua->agent("Stupid user agent check is stupid"); use FindBin; use lib "$FindBin::Bin/../lib"; @@ -40,13 +41,13 @@ my %classes = (Fighter => 'Fi', Corvette => 'Co', Frigate => 'Fr', Destroyer => my $file = get("http://game.planetarion.com/manual.pl?page=stats"); $dbh->begin_work; -my $st = $dbh->prepare(q{INSERT INTO ship_stats (name,"class",t1,t2,t3,"type",init,guns,armor,damage,eres,metal,crystal,eonium,race) VALUES(?,?,NULLIF(?,'-'),NULLIF(?,'-'),NULLIF(?,'-'),?,?,?,?,?,?,?,?,?,?)}); -while ($file =~ /((?:\w| )+)<\/td>(\w+)<\/td>(\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 $st = $dbh->prepare(q{INSERT INTO ship_stats (ship,"class",t1,t2,t3,"type",init,guns,armor,damage,eres,metal,crystal,eonium,race) VALUES(?,?,NULLIF(?,'-'),NULLIF(?,'-'),NULLIF(?,'-'),?,?,?,?,?,?,?,?,?,?)}); +while ($file =~ /class="(\w+)">((?:\w| )+)<\/td>(\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 = $10; $dmg = 0 if $dmg eq '-'; - my $class = $classes{$2}; - $st->execute($1,$class,$3,$4,$5,$6,$7,$8,$9,$dmg,$11,$12,$13,$14,$15) or die $dbh->errstr; - #print "$1,$class,$3,$4,$5,$6,$7,$dmg,$9,$10,$11,$12,$13,$14,$15\n"; + my $class = $classes{$3}; + $st->execute($2,$class,$4,$5,'-',$6,$7,$8,$9,$dmg,$11,$12,$13,$14,$1) or die $dbh->errstr; + print "$2,$class,$4,$5,'-',$6,$7,$dmg,$9,$10,$11,$12,$13,$14,$1\n"; } $dbh->commit;