Dominic J. Thoreau


#! /perl/bin/perl

#### Import football club names into football database
use strict;
use DOM_DB;

my $dbh=&db_connect('premiership');

my ($fh,$tag,$rank,$file,$id);
my (%fhn);
my (@filec, @fs);
# build master all 12 seasons all divisions
open (FILEINDEX,"fileindex.txt");
my @findex=;

# purge database
my $sql="DELETE FROM fixtures";         &exec_sql($sql);
   $sql="DELETE FROM results";          &exec_sql($sql);
   $sql="DELETE FROM teams";            &exec_sql($sql);

# reset all incremental counters   
$sql="ALTER TABLE teams AUTO_INCREMENT = 1";    &exec_sql($sql);
$sql="ALTER TABLE results AUTO_INCREMENT = 1";  &exec_sql($sql);

my (%tc)=();

# Get default rankings for team page
my (%start_rank,%code_id)=();
$sql="SELECT tag, start_rank, id FROM competitions";
my $csr=&select_sql($sql);
while (($tag,$rank,$id)=$csr->fetchrow) {

foreach $file (@findex) {
        chomp $file;
        open (FIND,$file);
        close FIND;

        my @fields=split(/\,/,$filec[0]);
        my $fc=0;

        # flush the key hash so we're not using out of date headers

        foreach $fh (@fields) {
        GAME: foreach $fh (@filec) {
                chomp $fh;
                if (not defined $fs[0]) {next GAME;}
                if ($fs[0]eq'Div'|| $fs[0]eq'') { next GAME; }
                # Date HomeTeam FTHG - FTAG AwayTeam
                my @date=split(/\//,$a);
                if ($date[2]>50) {$date[2]+=1900;} else {$date[2]+=2000;}

                if (defined $tc{$b}) { $tc{$b}=$code_id{$c}; }
                if (not defined $tc{$b}) {
                        INSERT INTO teams 
                        (name, start_rate, first_match,competition)
                        VALUES (?,?,?,?) };
                        # because these 2 clubs are synonyms
                                unless ($b eq 'Milton Keynes Dons' || $b eq 'Middlesbr');
$sql='UPDATE teams SET competition=? WHERE name=?';
foreach $fh (keys %tc) {
                unless ($b eq 'Milton Keynes Dons' || $b eq 'Middlesbr');

$sql = "UPDATE teams SET rate = start_rate";

# hard code the known synonyms.... *sigh*
$sql="UPDATE teams SET alt_name= ? WHERE name=?";
&exec_sql($sql,'Milton Keynes Dons','Wimbledon');

© 2004 Dominic J. Thoreau - this is
Updated and uploaded Fri Dec 29 11:45:07 2006