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, 8 months ago) by boris
Branches: MAIN
CVS tags: HEAD
Changed according to the new structure of the db

#!/usr/bin/perl -w

=pod

=head1 NAME

chronicles.pl - check references between chronicles and db

=head1 SYNOPSIS

chronicles.pl I<chronicles_dir>

=head1 DESCRIPTION

Check the references between database and chronicles. 


=head1 BUGS

The database, user and password are hardcoded. 

=head1 AUTHOR

Boris Veytsman 

=head1 $Id: chronicles.pl,v 1.5 2010/08/14 00:07:02 boris Exp $

=cut

    use strict;
use DBI;

# Creating hash dbtochronicles;
my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")
    or die "Can't connect to DB chgk\n";
my %dbtochronicles;
my $sth=$dbh->prepare("SELECT FileName,URL from Tournaments where 
 not isnull(URL) and Filename like '%.txt'");
$sth->execute;
while (my ($name,$url) = $sth->fetchrow_array) {
    $dbtochronicles{$name}=$url;
}


# Checking chronicles
if (! -d $ARGV[0]) {
    die "Cannot read $ARGV[0]";
}
chdir $ARGV[0] || die "Cannot chdir to $ARGV[0]: $!";
opendir (DIR, ".") || die "Cannot open $ARGV[0]: $!";
while (my $file=readdir(DIR)) {
    if (-f $file && $file =~ /html$/) {
	open (FILE, $file);
	while (<FILE>) {
	    chomp;
	    if (/http:\/\/db.chgk.info\/cgi-bin\/db.cgi\?tour=([^\"]*)\"/) {
		my $name="$1.txt";
		if (!exists($dbtochronicles{$name}) ||
		    $dbtochronicles{$name} !~ /$file$/) {
		    print "$file -> $name\n";
		} else {
		    delete($dbtochronicles{$name});
		}
	    }
	}
	close FILE;
    }
}
closedir DIR;
foreach my $name (keys %dbtochronicles) {
    if ($dbtochronicles{$name} =~ /boris/) {
	print "$name -> $dbtochronicles{$name}\n";
    }
}

exit 0;


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