]> ruin.nu Git - ndwebbie.git/blobdiff - scripts/fetchdumps.pl
Adding the perl and sql scripts
[ndwebbie.git] / scripts / fetchdumps.pl
diff --git a/scripts/fetchdumps.pl b/scripts/fetchdumps.pl
new file mode 100755 (executable)
index 0000000..efd124a
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/bin/perl
+q{
+/***************************************************************************
+ *   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+};
+
+use strict;
+use warnings;
+use DBI;
+use DBD::Pg qw(:pg_types);
+
+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';");
+
+my $insert = $dbh->prepare("INSERT INTO dumps(tick,type,modified,dump) VALUES(?,?,?,?)");
+my $select = $dbh->prepare("SELECT 1 FROM dumps WHERE type = ? AND modified = ?");
+my $updated = 0;
+for my $type ("planet","alliance","galaxy"){
+       my @head = head("http://game.planetarion.com/botfiles/${type}_listing.txt");
+       $select->execute($type,$head[2]);
+       unless ($select->fetchrow){
+               my $file = get("http://game.planetarion.com/botfiles/${type}_listing.txt");
+               if ($file =~ /Tick: (\d+)/){
+                       $updated = $1;
+                       $insert->execute($1,$type,$head[2],$file);
+               }
+       }
+       $select->finish;
+}
+
+if ($updated){
+       `${dir}parsedumps.pl $updated`;
+       `${dir}ndrank.pl`;
+       $dbh->do("UPDATE misc SET value = ? WHERE id = 'TICK'", undef, $updated);
+}
+
+
+$dbh->disconnect;