]> ruin.nu Git - ndwebbie.git/blob - scripts/ndrank.pl
Adding the perl and sql scripts
[ndwebbie.git] / scripts / ndrank.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;
29
30 our $dbh;
31 for my $file ("/home/whale/db.pl")
32 {
33         unless (my $return = do $file){
34                 warn "couldn't parse $file: $@" if $@;
35                 warn "couldn't do $file: $!"    unless defined $return;
36                 warn "couldn't run $file"       unless $return;
37         }
38 }
39
40 $dbh->begin_work;
41 my $st = $dbh->prepare(q{SELECT uid FROM current_planet_stats p JOIN users u ON p.id = u.planet WHERE alliance_id = 1 ORDER BY score DESC});
42 my $update = $dbh->prepare(q{UPDATE users SET rank = ? WHERE uid = ?});
43 $st->execute;
44 my $rank = 1;
45 while (my ($uid) = $st->fetchrow){
46         $update->execute($rank,$uid);
47         $rank++;
48 }
49
50 $dbh->commit;
51
52 $dbh->disconnect;