Annotation of db/prgsrc/chronicles.pl, revision 1.5

1.1       boris       1: #!/usr/bin/perl -w
                      2: 
                      3: =pod
                      4: 
                      5: =head1 NAME
                      6: 
                      7: chronicles.pl - check references between chronicles and db
                      8: 
                      9: =head1 SYNOPSIS
                     10: 
                     11: chronicles.pl I<chronicles_dir>
                     12: 
                     13: =head1 DESCRIPTION
                     14: 
                     15: Check the references between database and chronicles. 
                     16: 
                     17: 
                     18: =head1 BUGS
                     19: 
                     20: The database, user and password are hardcoded. 
                     21: 
                     22: =head1 AUTHOR
                     23: 
                     24: Boris Veytsman 
                     25: 
1.5     ! boris      26: =head1 $Id: chronicles.pl,v 1.4 2003/03/17 15:49:27 boris Exp $
1.1       boris      27: 
                     28: =cut
1.2       boris      29: 
                     30:     use strict;
                     31: use DBI;
                     32: 
                     33: # Creating hash dbtochronicles;
                     34: my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")
                     35:     or die "Can't connect to DB chgk\n";
                     36: my %dbtochronicles;
1.5     ! boris      37: my $sth=$dbh->prepare("SELECT FileName,URL from Tournaments where 
        !            38:  not isnull(URL) and Filename like '%.txt'");
1.2       boris      39: $sth->execute;
                     40: while (my ($name,$url) = $sth->fetchrow_array) {
                     41:     $dbtochronicles{$name}=$url;
                     42: }
                     43: 
                     44: 
                     45: # Checking chronicles
                     46: if (! -d $ARGV[0]) {
                     47:     die "Cannot read $ARGV[0]";
                     48: }
                     49: chdir $ARGV[0] || die "Cannot chdir to $ARGV[0]: $!";
                     50: opendir (DIR, ".") || die "Cannot open $ARGV[0]: $!";
                     51: while (my $file=readdir(DIR)) {
                     52:     if (-f $file && $file =~ /html$/) {
                     53:        open (FILE, $file);
                     54:        while (<FILE>) {
                     55:            chomp;
1.5     ! boris      56:            if (/http:\/\/db.chgk.info\/cgi-bin\/db.cgi\?tour=([^\"]*)\"/) {
1.2       boris      57:                my $name="$1.txt";
                     58:                if (!exists($dbtochronicles{$name}) ||
                     59:                    $dbtochronicles{$name} !~ /$file$/) {
                     60:                    print "$file -> $name\n";
                     61:                } else {
                     62:                    delete($dbtochronicles{$name});
                     63:                }
                     64:            }
                     65:        }
                     66:        close FILE;
                     67:     }
                     68: }
                     69: closedir DIR;
                     70: foreach my $name (keys %dbtochronicles) {
1.4       boris      71:     if ($dbtochronicles{$name} =~ /boris/) {
1.3       boris      72:        print "$name -> $dbtochronicles{$name}\n";
                     73:     }
1.2       boris      74: }
                     75: 
                     76: exit 0;
                     77: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>