]> ruin.nu Git - ndwebbie.git/blob - scripts/stats.pl
Use new race infrastructure for members stats
[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 use Data::Dumper;
28
29 use LWP::Simple qw/get $ua/;
30 $ua->agent("Stupid user agent check is stupid");
31
32 use FindBin;
33 use lib "$FindBin::Bin/../lib";
34
35 use ND::DB;
36 use NDWeb::Stats;
37
38 our $dbh = ND::DB::DB();
39
40 my $file = get("http://game.planetarion.com/manual.pl?action=statsxml");
41 $dbh->begin_work;
42 my $st = $dbh->prepare(q{
43 INSERT INTO ship_stats
44         (ship,"class",t1,t2,t3,"type",init,guns,armor,damage,eres,metal,crystal,eonium,race, cloaked, baseeta)
45         VALUES(?,?,NULLIF(?,'-'),NULLIF(?,'-'),NULLIF(?,'-'),?,?,?,?,?,?,?,?,?,(SELECT race FROM races WHERE race_name = ?), ?, ?)});
46
47 my @columns = qw/ship class t1 t2 t3 type init guns armor damage eres metal crystal eonium race cloaked baseeta/;
48
49 my @ships = parseStats($file);
50 for my $ship (@ships) {
51         my @data;
52         for my $c (@columns) {
53                 push @data, $ship->{$c};
54         }
55         #print Dumper(\@data), "\n";
56         print "@data\n";
57         $st->execute(@data) or die $dbh->errstr;
58 }
59
60
61 $dbh->commit;
62
63 $dbh->disconnect;