File:  [Local Repository] / db / prgsrc / chronicles.pl
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Sat Aug 14 00:07:02 2010 UTC (13 years, 9 months ago) by boris
Branches: MAIN
CVS tags: HEAD
Changed according to the new structure of the db

    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: 
   26: =head1 $Id: chronicles.pl,v 1.5 2010/08/14 00:07:02 boris Exp $
   27: 
   28: =cut
   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;
   37: my $sth=$dbh->prepare("SELECT FileName,URL from Tournaments where 
   38:  not isnull(URL) and Filename like '%.txt'");
   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;
   56: 	    if (/http:\/\/db.chgk.info\/cgi-bin\/db.cgi\?tour=([^\"]*)\"/) {
   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) {
   71:     if ($dbtochronicles{$name} =~ /boris/) {
   72: 	print "$name -> $dbtochronicles{$name}\n";
   73:     }
   74: }
   75: 
   76: exit 0;
   77: 

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