version 1.6, 2000/10/22 01:25:25
|
version 1.12, 2008/11/14 11:23:03
|
Line 6 updateindex.pl - a script for creation o
|
Line 6 updateindex.pl - a script for creation o
|
|
|
=head1 SYNOPSIS |
=head1 SYNOPSIS |
|
|
updateind.pl [B<-i> I<indexfile>] [B<-y>|B<-n>] |
updateind.pl [B<-i> I<indexfile>] [B<-y>|B<-n>] [B<-r>] |
|
|
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
Line 42 Answer 'yes' to all questions
|
Line 42 Answer 'yes' to all questions
|
|
|
Answer 'no' to all questions |
Answer 'no' to all questions |
|
|
|
=item B<-r> |
|
|
|
Remove all entries with zero QuestionNum |
|
|
=head1 BUGS |
=head1 BUGS |
|
|
The database, user and password are hardcoded. |
The database, user and password are hardcoded. |
Line 59 Boris Veytsman
|
Line 63 Boris Veytsman
|
=cut |
=cut |
|
|
use strict; |
use strict; |
use vars qw($opt_i $opt_h $opt_y $opt_n); |
use vars qw($opt_i $opt_h $opt_y $opt_n $opt_r); |
|
|
use Getopt::Std; |
use Getopt::Std; |
use DBI; |
use DBI; |
|
|
MAIN: |
MAIN: |
{ |
{ |
my $USAGE="Usage: updateindex.pl [-i indexfile] [-y|-n]\n"; |
my $USAGE="Usage: updateindex.pl [-i indexfile] [-y|-n][-r]\n"; |
getopts('hi:yn') or die $USAGE; |
my $REMOVE=0; |
|
getopts('hi:ynr') or die $USAGE; |
if ($opt_h) { |
if ($opt_h) { |
print $USAGE; |
print $USAGE; |
exit 0; |
exit 0; |
Line 79 MAIN:
|
Line 84 MAIN:
|
if ($opt_n ) { |
if ($opt_n ) { |
$decision = 'no'; |
$decision = 'no'; |
} |
} |
|
if ($opt_r) { |
|
$REMOVE=1; |
|
} |
my($source) = $opt_i; |
my($source) = $opt_i; |
|
my $champ; |
my($depth, @depthId); |
my($depth, @depthId); |
my $filename; |
my $filename; |
my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") |
my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") |
or die "Can't connect to DB chgk\n"; |
or die "Can't connect to DB chgk\n"; |
|
if ($dbh->get_info( 18 )=~/^(5|(4.1))/) {$dbh->do("SET NAMES 'koi8r'");} |
if ($source) { |
if ($source) { |
open INFO, $source or die "Can't open input file: $!\n"; |
open INFO, $source or die "Can't open input file: $!\n"; |
} else { |
} else { |
*INFO=*STDIN; |
*INFO=*STDIN; |
} |
} |
|
|
while (<INFO>) { |
while (<INFO>) { |
chomp; |
chomp; |
s/
//; |
s/
//; |
next if (/^\s*$/); |
next if (/^\s*$/); |
if (s/^(\S+) *//) { # File found |
if (s/^(\S+\.txt) *//) { # File found |
$filename = $1; |
$filename = $1; |
$depth = -1; |
$depth = -1; |
|
$champ=1; |
} else { # Group found |
} else { # Group found |
$filename = ''; |
if (s/^(\S+)//) |
|
{ $filename = $1;} |
|
else |
|
{$filename = ''} |
$depth = -2; |
$depth = -2; |
|
$champ=0; |
} |
} |
s/^(\t*)//; |
s/^(\t*)//; |
$depth += length($1); |
$depth += length($1); |
Line 111 MAIN:
|
Line 126 MAIN:
|
my $title = $_; |
my $title = $_; |
my $ParentId = ($depth) ? $depthId[$depth - 1] : 0; |
my $ParentId = ($depth) ? $depthId[$depth - 1] : 0; |
my $Id = CheckId($dbh,$title,$ParentId,$decision,$filename); |
my $Id = CheckId($dbh,$title,$ParentId,$decision,$filename); |
if (!$Id || $filename) { |
if (!$Id || $champ) { |
next; |
next; |
} |
} |
$depthId[$depth] = $Id; |
$depthId[$depth] = $Id; |
Line 119 MAIN:
|
Line 134 MAIN:
|
} |
} |
print STDERR "Всего вопросов: ", |
print STDERR "Всего вопросов: ", |
UpdateGroup($dbh,0),"\n"; |
UpdateGroup($dbh,0),"\n"; |
|
if ($REMOVE) { |
|
print STDERR "Removing empty tours."; |
|
$dbh->do("DELETE FROM Tournaments WHERE QuestionsNum=0"); |
|
} |
|
$dbh->do("INSERT INTO Tournaments |
|
(Id, Title, ParentId, Type,CreatedAt) |
|
VALUES |
|
(9999, 'Несортированные турниры', 0,'Г',NOW())"); |
|
|
$dbh->disconnect; |
$dbh->disconnect; |
} |
} |
|
|
Line 128 sub CheckId {
|
Line 152 sub CheckId {
|
my $type; |
my $type; |
my $key; |
my $key; |
my $value; |
my $value; |
my $Id = 0; |
my $Id = 0; |
if ($filename) { |
if ($filename && $filename=~/\.txt/) { |
$type=$dbh->quote('Ч'); |
$type=$dbh->quote('Ч'); |
$key = "FileName"; |
} else {$type=$dbh->quote('Г');} |
$value = $dbh->quote($filename); |
if ($filename) |
|
{ |
|
$key = "FileName"; |
|
$value = $dbh->quote($filename); |
} else { |
} else { |
$type=$dbh->quote('Г'); |
$key = "Title"; |
$key = "Title"; |
$value = $dbh->quote($title); |
$value = $dbh->quote($title); |
|
} |
} |
|
|
$title=$dbh->quote($title); |
$title=$dbh->quote($title); |
my $sth = $dbh->prepare("SELECT Id FROM Tournaments |
my $sth = $dbh->prepare("SELECT Id FROM Tournaments |
WHERE $key=$value"); |
WHERE $key=$value"); |
Line 165 sub CheckId {
|
Line 192 sub CheckId {
|
|
|
} else { |
} else { |
$sth = $dbh->prepare("INSERT INTO Tournaments |
$sth = $dbh->prepare("INSERT INTO Tournaments |
(Title, ParentId, Type) |
(Title, ParentId, Type,CreatedAt) |
VALUES |
VALUES |
($title, $ParentId,$type)"); |
($title, $ParentId,$type,NOW())"); |
} |
} |
$sth->execute or die $dbh->errstr; |
$sth->execute or die $dbh->errstr; |
if (!$Id) { |
if (!$Id) { |