]> ruin.nu Git - ndwebbie.git/blobdiff - scripts/fetchdumps.pl
Use new race infrastructure for members stats
[ndwebbie.git] / scripts / fetchdumps.pl
index efd124afc154c7688472c4e6219dab2ecace08e0..4a7ae1b6b774dd5b6226614b812a63dc0cad5bbb 100755 (executable)
@@ -22,23 +22,19 @@ q{
 
 use strict;
 use warnings;
+use local::lib;
 use DBI;
 use DBD::Pg qw(:pg_types);
 
-use LWP::Simple;
+use LWP::Simple qw/head get $ua/;
+$ua->agent("Stupid user agent check is stupid");
 
-$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 FindBin;
+use lib "$FindBin::Bin/../lib";
+
+use ND::DB;
+
+our $dbh = ND::DB::DB();
 
 my $insert = $dbh->prepare("INSERT INTO dumps(tick,type,modified,dump) VALUES(?,?,?,?)");
 my $select = $dbh->prepare("SELECT 1 FROM dumps WHERE type = ? AND modified = ?");
@@ -48,7 +44,7 @@ for my $type ("planet","alliance","galaxy"){
        $select->execute($type,$head[2]);
        unless ($select->fetchrow){
                my $file = get("http://game.planetarion.com/botfiles/${type}_listing.txt");
-               if ($file =~ /Tick: (\d+)/){
+               if (defined $file && $file =~ /Tick: (\d+)/){
                        $updated = $1;
                        $insert->execute($1,$type,$head[2],$file);
                }
@@ -57,9 +53,11 @@ for my $type ("planet","alliance","galaxy"){
 }
 
 if ($updated){
-       `${dir}parsedumps.pl $updated`;
-       `${dir}ndrank.pl`;
-       $dbh->do("UPDATE misc SET value = ? WHERE id = 'TICK'", undef, $updated);
+       system("$FindBin::Bin/parsetick.sh", $updated);
+       system("$FindBin::Bin/ndrank.pl");
+       $dbh->do(q{UPDATE misc SET value = ? WHERE id = 'TICK'}, undef, $updated);
+       system 'killall','-USR1', 'ndbot.pl';
+       local $dbh->{Warn} = 0;
 }