version 1.1, 2002/01/12 05:00:30
|
version 1.2, 2002/01/15 03:34:31
|
Line 1
|
Line 1
|
|
#!perl |
use DBI; |
use DBI; |
@months=('000','Jan',"Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct", |
@months=('000','Jan',"Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct", |
"Nov","Dec"); |
"Nov","Dec"); |
|
|
open WARN ,"warn"; |
|
$fname=shift; |
$fname=shift; |
$fname=~s/\.txt$//; |
$fname=~s/\.txt$//; |
|
$TMPDIR="new"; |
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 (WriteFile($fname)==-1) {print "File?";} |
if (WriteFile($dbh,$fname)==-1) {print "File?";} |
|
|
|
$dbh->disconnect; |
|
|
|
|
|
sub PrintDate { |
|
my $date=shift; |
|
my ($year,$month,$day)=split /-/, $date; |
|
# $month=0,$date=0 if $year && $month==1 && $day==1; |
|
return sprintf("%02d-%3s-%04d",$day,$months[$month],$year); |
|
} |
|
|
sub WriteFile { |
sub WriteFile { |
my ($fname) = @_; |
my ($dbh,$fname) = @_; |
|
$fname=~s/\.txt$//; |
|
$fname=~s/.*\/(\w+)/$1/; |
my $query= "SELECT Id, Title, Copyright, Info, URL, |
my $query= "SELECT Id, Title, Copyright, Info, URL, |
Editors, EnteredBy, PlayedAt, CreatedAt |
Editors, EnteredBy, PlayedAt, CreatedAt |
from Tournaments where FileName=".$dbh->quote("$fname.txt"); |
from Tournaments where FileName=".$dbh->quote("$fname.txt"); |
$sth=$dbh->prepare($query); |
my $sth=$dbh->prepare($query); |
|
my (%Question,%editor,%qnumber,%copyright,%author,%vid,%tourtitle); |
$sth->execute; |
$sth->execute; |
($Id, $Title, $Copyright, $Info, $URL, |
my ($Id, $Title, $Copyright, $Info, $URL, |
$Editors, $EnteredBy, $PlayedAt, $CreatedAt)= |
$Editors, $EnteredBy, $PlayedAt, $CreatedAt)= |
$sth->fetchrow; |
$sth->fetchrow; |
return -1 unless $Id; |
return -1 unless $Id; |
open (OUT, ">new/$fname.txt"); |
open (OUT, ">$TMPDIR/$fname.txt"); |
print OUT "Чемпионат:\n$Title\n\n"; |
print OUT "Чемпионат:\n$Title\n\n"; |
my $date=$PlayedAt; |
|
($year,$month,$day)=split /-/, $date; |
|
# $month=0,$date=0 if $year && $month==1 && $day==1; |
|
$pdate=sprintf("%02d-%3s-%4d",$day,$months[$month],$year); |
|
|
|
print OUT "Дата:\n$pdate\n\n" if $date; |
|
|
|
print OUT "URL:\n$URL\n\n" if $URL; |
print OUT "URL:\n$URL\n\n" if $URL; |
|
|
Line 41 sub WriteFile {
|
Line 46 sub WriteFile {
|
|
|
print OUT "Редактор:\n$Editors\n\n" if $Editors; |
print OUT "Редактор:\n$Editors\n\n" if $Editors; |
|
|
|
print OUT "Дата:\n".PrintDate($PlayedAt)."\n\n" if $PlayedAt; |
|
|
$query= "SELECT Id, Title, Copyright, Editors from Tournaments where ParentId=$Id order by Id"; |
|
|
$query= "SELECT Id, Title, Copyright, Editors, PlayedAt from Tournaments where ParentId=$Id order by Id"; |
$sth=$dbh->prepare($query); |
$sth=$dbh->prepare($query); |
$sth->execute; |
$sth->execute; |
while (($tourid,$tourtitle,$cright,$editor)=$sth->fetchrow,$tourid) |
my ($tourid,$tourtitle,$cright,$editor,@tours,$vid,$author,$tourauthor); |
|
|
|
|
|
while (($tourid,$tourtitle,$cright,$editor,$date)=$sth->fetchrow,$tourid) |
{ |
{ |
# $text{$tourid}="Тур:\n$tourtitle\n\n"; |
# $text{$tourid}="Тур:\n$tourtitle\n\n"; |
$query= "SELECT * from Questions where ParentId=$tourid order by QuestionId"; |
$query= "SELECT * from Questions where ParentId=$tourid order by QuestionId"; |
$sth1=$dbh->prepare($query); |
my $sth1=$dbh->prepare($query); |
$sth1->execute; |
$sth1->execute; |
push(@tours,$tourid); |
push(@tours,$tourid); |
$tourtitle{$tourid}=$tourtitle; |
$tourtitle{$tourid}=$tourtitle; |
$copyright{$tourid}=$cright; |
$copyright{$tourid}=$cright; |
$editor{$tourid}=$editor; |
$editor{$tourid}=$editor; |
|
$date{$tourid}=$date; |
$vid=''; |
$vid=''; |
$author=''; |
my $author=''; |
$eqauthor=1; |
my $eqauthor=1; |
$qnumber=0; |
my $qnumber=0; |
while (@arr=$sth1->fetchrow, $arr[0]) |
my @arr; |
|
while ( @arr=$sth1->fetchrow, $arr[0]) |
{ |
{ |
my($i, $name) = 0; |
my $i = 0; |
$qnumber++; |
$qnumber++; |
foreach $name (@{$sth1->{NAME}}) { |
|
$arr[$i]=~s/^(.*?)\s*$/$1/; |
foreach my $name (@{$sth1->{NAME}}) { |
|
$arr[$i]=~s/^(.*?)\s*$/$1/ if $arr[$i]; |
$Question{$tourid}[$qnumber]{$name} = $arr[$i++]; |
$Question{$tourid}[$qnumber]{$name} = $arr[$i++]; |
} |
} |
if ($vid) |
if ($vid) |
{ |
{ |
if ($vid ne $Question{$tourid}[$qnumber]{'Type'}) {print WARN "Warning: Different types for Tournament $tourid\n"} |
if ($vid ne $Question{$tourid}[$qnumber]{'Type'}) {print STDERR "Warning: Different types for Tournament $tourid\n"} |
} else |
} else |
{ |
{ |
$vid=$Question{$tourid}[$qnumber]{'Type'}; |
$vid=$Question{$tourid}[$qnumber]{'Type'}; |
} |
} |
|
|
|
|
if ($author) |
if ($author) |
{ |
{ |
if ($author ne $Question{$tourid}[$qnumber]{'Authors'}) |
if ($author ne $Question{$tourid}[$qnumber]{'Authors'}) |
Line 94 sub WriteFile {
|
Line 108 sub WriteFile {
|
|
|
|
|
$vid=''; |
$vid=''; |
$eqvid=1; |
my $eqvid=1; |
$eqauthor=1; |
my $eqauthor=1; |
|
my $eqdate=1; |
|
$date=''; |
|
|
|
|
foreach (@tours) |
foreach (@tours) |
{ |
{ |
$vid||=$vid{$_}; |
$vid||=$vid{$_}; |
Line 108 sub WriteFile {
|
Line 126 sub WriteFile {
|
{ |
{ |
$eqauthor=0; |
$eqauthor=0; |
} |
} |
|
$date||=$date{$_}; |
|
if (!$date{$_} || ($date{$_} ne $date)) |
|
{ |
|
$eqdate=0; |
|
} |
} |
} |
|
|
print OUT "Вид:\n$vid\n\n" if $eqvid; |
print OUT "Вид:\n$vid\n\n" if $eqvid; |
print OUT "Автор:\n$author\n\n" if $eqauthor; |
print OUT "Автор:\n$author\n\n" if $eqauthor; |
|
|
foreach $tour(@tours) |
foreach my $tour(@tours) |
{ |
{ |
print OUT "Тур:\n$tourtitle{$tour}\n\n"; |
print OUT "Тур:\n$tourtitle{$tour}\n\n"; |
print OUT "Вид:\n$vid{$tour}\n\n" if !$eqvid; |
print OUT "Вид:\n$vid{$tour}\n\n" if !$eqvid; |
print OUT "Копирайт:\n$copyright{$tour}\n\n" if $copyright{$tour} && ($copyright{$tour} ne $Copyright); |
print OUT "Копирайт:\n$copyright{$tour}\n\n" if $copyright{$tour} && ($copyright{$tour} ne $Copyright); |
print OUT "Редактор:\n$editor{$tour}\n\n" if $editor{$tour} && ($editor{$tour} ne $Editors); |
print OUT "Редактор:\n$editor{$tour}\n\n" if $editor{$tour} && ($editor{$tour} ne $Editors); |
|
print OUT "Дата:\n".PrintDate($date{$tour})."\n\n" if !$eqdate && $date{$tour} || !$PlayedAt; |
$tourauthor=0; |
$tourauthor=0; |
if (!$eqauthor && $author{$tour}) |
if (!$eqauthor && $author{$tour}) |
{ |
{ |
print OUT "Автор:\n$author{$tour}\n\n"; |
print OUT "Автор:\n$author{$tour}\n\n"; |
$tourauthor=1; |
$tourauthor=1; |
} |
} |
foreach $q(1..$qnumber{$tour}) |
foreach my $q(1..$qnumber{$tour}) |
{ |
{ |
print OUT "Вопрос $q:\n".$Question{$tour}[$q]{'Question'}."\n\n"; |
print OUT "Вопрос $q:\n".$Question{$tour}[$q]{'Question'}."\n\n"; |
print OUT "Ответ:\n".$Question{$tour}[$q]{'Answer'}."\n\n"; |
print OUT "Ответ:\n".$Question{$tour}[$q]{'Answer'}."\n\n"; |
Line 145 sub WriteFile {
|
Line 168 sub WriteFile {
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|