From: Michael Andreen Date: Sat, 12 Jan 2008 14:37:56 +0000 (+0100) Subject: Use ND::DB module instead of db.pl X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=commitdiff_plain;h=83be73d01437ba9841257bb9064314d63fab9487 Use ND::DB module instead of db.pl --- diff --git a/scripts/fetchdumps.pl b/scripts/fetchdumps.pl index efd124a..b8be1c3 100755 --- a/scripts/fetchdumps.pl +++ b/scripts/fetchdumps.pl @@ -27,17 +27,11 @@ 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; - } -} +use lib qw{/var/www/ndawn/}; +use ND::DB; + +our $dbh = ND::DB::DB(); + $dbh->do("SET CLIENT_ENCODING TO 'LATIN1';"); my $insert = $dbh->prepare("INSERT INTO dumps(tick,type,modified,dump) VALUES(?,?,?,?)"); @@ -57,8 +51,8 @@ for my $type ("planet","alliance","galaxy"){ } if ($updated){ - `${dir}parsedumps.pl $updated`; - `${dir}ndrank.pl`; + `/var/www/ndawn/scripts/parsedumps.pl $updated`; + `/var/www/ndawn/scripts/ndrank.pl`; $dbh->do("UPDATE misc SET value = ? WHERE id = 'TICK'", undef, $updated); } diff --git a/scripts/ndrank.pl b/scripts/ndrank.pl index cc7c127..be8b1cc 100755 --- a/scripts/ndrank.pl +++ b/scripts/ndrank.pl @@ -27,15 +27,10 @@ use DBD::Pg qw(:pg_types); use LWP::Simple; -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; - } -} +use lib qw{/var/www/ndawn/}; +use ND::DB; + +our $dbh = ND::DB::DB(); $dbh->begin_work; 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}); diff --git a/scripts/parsedumps.pl b/scripts/parsedumps.pl index f1738bf..d22525f 100755 --- a/scripts/parsedumps.pl +++ b/scripts/parsedumps.pl @@ -30,17 +30,9 @@ use LWP::Simple; use lib qw{/var/www/ndawn/}; use ND::Include; +use ND::DB; -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->trace("0","/tmp/parsedumps"); +our $dbh = ND::DB::DB(); $ND::DBH = $dbh; diff --git a/scripts/reset_hosts.pl b/scripts/reset_hosts.pl index 4932f05..a86ea3c 100755 --- a/scripts/reset_hosts.pl +++ b/scripts/reset_hosts.pl @@ -6,18 +6,12 @@ use DBI; use DBD::Pg qw(:pg_types); use LWP::Simple; +use lib qw{/var/www/ndawn/}; +use ND::DB; -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; - } -} +our $dbh = ND::DB::DB(); -$dbh->trace("0","/tmp/scanstest"); +#$dbh->trace("0","/tmp/scanstest"); my $update = $dbh->prepare("UPDATE users SET hostmask = pnick || '.users.netgamers.org' where hostmask ilike '%.%' AND NOT hostmask ilike pnick || '.users.netgamers.org'"); $update->execute(); $dbh->disconnect; diff --git a/scripts/stats.pl b/scripts/stats.pl index ad8fc00..bcac7fe 100755 --- a/scripts/stats.pl +++ b/scripts/stats.pl @@ -26,18 +26,11 @@ use DBI; use DBD::Pg qw(:pg_types); use LWP::Simple; +use lib qw{/var/www/ndawn/}; +use ND::DB; + +our $dbh = ND::DB::DB(); -$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 %classes = (Fighter => 'Fi', Corvette => 'Co', Frigate => 'Fr', Destroyer => 'De', Cruiser => 'Cr', Battleship => 'Bs'); diff --git a/scripts/tick.pl b/scripts/tick.pl index bb652a8..6b97aa1 100755 --- a/scripts/tick.pl +++ b/scripts/tick.pl @@ -7,17 +7,11 @@ use DBD::Pg qw(:pg_types); use LWP::Simple; -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; - } -} +use lib qw{/var/www/ndawn/}; +use ND::DB; + +our $dbh = ND::DB::DB(); -$dbh->trace("0","/tmp/scanstest"); my $update = $dbh->prepare("UPDATE misc SET value = value::int + 1 WHERE id = 'TICK'"); $update->execute(); $dbh->disconnect;