]> ruin.nu Git - ndwebbie.git/blob - scripts/stats.pl
LWP::Simple fix for cloudfare
[ndwebbie.git] / scripts / stats.pl
1 #!/usr/bin/perl
2 q{
3 /***************************************************************************
4  *   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
20  ***************************************************************************/
21 };
22
23 use strict;
24 use warnings;
25 use DBI;
26 use DBD::Pg qw(:pg_types);
27
28 use LWP::Simple qw/get $ua/;
29 $ua->agent("Stupid user agent check is stupid");
30
31 use FindBin;
32 use lib "$FindBin::Bin/../lib";
33
34 use ND::DB;
35
36 our $dbh = ND::DB::DB();
37
38 $dbh->do("SET CLIENT_ENCODING TO 'LATIN1';");
39
40 my %classes = (Fighter => 'Fi', Corvette => 'Co', Frigate => 'Fr', Destroyer => 'De', Cruiser => 'Cr', Battleship => 'Bs');
41
42 my $file = get("http://game.planetarion.com/manual.pl?page=stats");
43 $dbh->begin_work;
44 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(?,'-'),?,?,?,?,?,?,?,?,?,?)});
45 while ($file =~ /((?:\w| )+)<\/td><td>(\w+)<\/td><td>(\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){
46         my $dmg = $10;
47         $dmg = 0 if $dmg eq '-';
48         my $class = $classes{$2};
49         $st->execute($1,$class,$3,$4,$5,$6,$7,$8,$9,$dmg,$11,$12,$13,$14,$15) or die $dbh->errstr;
50         #print "$1,$class,$3,$4,$5,$6,$7,$dmg,$9,$10,$11,$12,$13,$14,$15\n";
51 }
52
53 $dbh->commit;
54
55 $dbh->disconnect;