version 1.12, 2000/10/22 02:25:02
|
version 1.18, 2000/11/11 03:58:59
|
Line 33 my (%RevMonths) =
|
Line 33 my (%RevMonths) =
|
'JAN', '1', 'FEB', '2', 'MAR', '3', 'APR', '4', 'MAY', '5', 'JUN', '6', |
'JAN', '1', 'FEB', '2', 'MAR', '3', 'APR', '4', 'MAY', '5', 'JUN', '6', |
'JUL', '7', 'AUG', '8', 'SEP', '9', 'OCT', '10', 'NOV', '11', |
'JUL', '7', 'AUG', '8', 'SEP', '9', 'OCT', '10', 'NOV', '11', |
'DEC', '12', |
'DEC', '12', |
'Янв', '0', 'Фев', 1, 'Мар', 2, 'Апр', 3, 'Май', '4', |
'Янв', '1', 'Фев', '2', 'Мар', '3', 'Апр', '4', 'Май', '5', |
'Июн', '5', 'Июл', 6, 'Авг', '7', 'Сен', '8', |
'Июн', '6', 'Июл', '7', 'Авг', '8', 'Сен', '9', |
'Окт', '9', 'Ноя', '19', 'Дек', '11'); |
'Окт', '10', 'Ноя', '11', 'Дек', '12'); |
my ($sth); |
my ($sth); |
|
|
use vars qw($/); |
|
|
|
|
|
|
|
Line 78 sub getField {
|
Line 78 sub getField {
|
} |
} |
next if (/^\s*$/); |
next if (/^\s*$/); |
|
|
if (s/^(.*?)[:\.]\s*// && !$key) { |
if (!$key && /^(.*?)[:\.]\s*(.*)$/s) { |
$key = $1; |
$key = $1; |
$value=$_; |
$value=$2; |
next; |
next; |
} |
} |
if ($key) { |
if ($key) { |
Line 198 sub GetTours {
|
Line 198 sub GetTours {
|
return @Tours; |
return @Tours; |
} |
} |
|
|
|
sub CreateTour { |
|
my ($dbh,$title,$ParentId,$TourNum,$rh_defaults)=@_; |
|
my $sth = $dbh->prepare("INSERT INTO Tournaments |
|
(Title, Type, ParentId, Number) |
|
VALUES ($title, 'Т', $ParentId, $TourNum)"); |
|
$sth->execute; |
|
my $TourId = $sth->{mysql_insertid}; |
|
while (my ($key,$value)=each %$rh_defaults) { |
|
&UpdateTournament($dbh, $TourId, $key, $value); |
|
} |
|
return $TourId; |
|
} |
|
|
|
|
MAIN: |
MAIN: |
{ |
{ |
my($key, $value, $addition); |
my($key, $value, $addition); |
|
# |
|
# Inherited fields for a Tour or Tournament |
|
# |
|
my %TourFields = ('Копирайт' => 'Copyright', |
|
'Инфо' => 'Info', 'URL' => 'URL', |
|
'Ссылка' => 'URL', 'Редактор' => 'Editors', |
|
'Обработан'=> 'EnteredBy', |
|
'Дата'=>'PlayedAt'); |
|
# |
|
# Inherited fields for a Question |
|
# |
|
my %QuestionFields = ('Тип'=> 'Type', 'Вид'=> 'Type', |
|
'Автор' => 'Authors', 'Рейтинг'=>'Rating', |
|
'Источник' => 'Sources'); |
|
|
|
|
my($source); |
my($source); |
|
|
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"; |
|
|
while ($source = shift) { |
while ($source = shift) { |
|
my $TourNum=0; |
my($PlayedAt) = ''; |
my($PlayedAt) = ''; |
my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0); |
my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0); |
my($tournum, $qnum, $all_qnum, $qtype) = (0, 0, 0, 'Ч'); |
my($tournum, $qnum, $all_qnum) = (0, 0, 0); |
my (@d) = (localtime((stat($source))[9]))[5,4,3]; |
my (@d) = (localtime((stat($source))[9]))[5,4,3]; |
$d[1]++; |
$d[1]++; |
$d[0]+=1900; |
$d[0]+=1900; |
Line 223 MAIN:
|
Line 252 MAIN:
|
$source =~ s/^.*\/([^\/]*)$/$1/; |
$source =~ s/^.*\/([^\/]*)$/$1/; |
$source = $dbh->quote($source); |
$source = $dbh->quote($source); |
print STDERR "Файл: $source, дата: $CreatedAt "; |
print STDERR "Файл: $source, дата: $CreatedAt "; |
|
my %TourDefaults=('CreatedAt'=>$CreatedAt); |
|
my %QuestionDefaults=(); |
|
my %QuestionGlobalDefaults=('Type'=>$dbh->quote('Ч')); |
while (($key, $value) = getField(\*INFD, $dbh)) { |
while (($key, $value) = getField(\*INFD, $dbh)) { |
last if (!$key); |
last if (!$key); |
|
|
Line 250 MAIN:
|
Line 282 MAIN:
|
WHERE Id=$TourId"); |
WHERE Id=$TourId"); |
} |
} |
$qnum = 0; |
$qnum = 0; |
$sth = $dbh->prepare("INSERT INTO Tournaments |
$TourNum++; |
(Title, Type, ParentId, CreatedAt) |
$TourId=CreateTour($dbh,$value,$TournamentId,$TourNum, |
VALUES ($value, 'Т', $TournamentId, |
\%TourDefaults); |
$CreatedAt)"); |
%QuestionDefaults=%QuestionGlobalDefaults; |
$sth->execute; |
$QuestionId=0; |
$TourId = $sth->{mysql_insertid}; |
next; |
next; |
|
} |
|
if ($key =~ /Вид/ || $key =~ /Тип/) { |
|
$qtype = $value; |
|
$qtype =~ s/\'//g; |
|
next; |
|
} |
} |
if ($key =~ /Вопрос/) { |
if ($key =~ /Вопрос/) { |
if (!$TourId) { |
if (!$TourId) { |
$qnum = 0; |
$qnum = 0; |
$sth = $dbh->prepare("INSERT INTO Tournaments |
$TourId=CreateTour($dbh,'1',$TournamentId, |
(Title, Type, ParentId, CreatedAt) |
\%TourDefaults); |
VALUES ('1', 'Т', $TournamentId, |
%QuestionDefaults=%QuestionGlobalDefaults; |
$CreatedAt)"); |
|
$sth->execute; |
|
$TourId = $sth->{mysql_insertid}; |
|
} |
} |
my $query = "INSERT INTO Questions |
my $query = "INSERT INTO Questions |
(ParentId, Number, Type) |
(ParentId, Number) |
VALUES ($TourId, $qnum+1, \'$qtype\')"; |
VALUES ($TourId, $qnum+1)"; |
$sth = $dbh->prepare($query); |
$sth = $dbh->prepare($query); |
$sth->execute or print $query;; |
$sth->execute or print $query;; |
$QuestionId = $sth->{mysql_insertid}; |
$QuestionId = $sth->{mysql_insertid}; |
&UpdateQuestion($dbh, $QuestionId, "Question", $value); |
&UpdateQuestion($dbh, $QuestionId, "Question", $value); |
|
while (my ($key,$value)=each %QuestionDefaults) { |
|
&UpdateQuestion($dbh, $QuestionId, $key, $value); |
|
} |
$qnum++; |
$qnum++; |
$all_qnum++; |
$all_qnum++; |
next; |
next; |
Line 290 MAIN:
|
Line 316 MAIN:
|
next; |
next; |
} |
} |
|
|
if ($key =~ /Рейтинг/) { |
|
&UpdateQuestion($dbh, $QuestionId, "Rating", $value); |
|
next; |
|
} |
|
|
|
|
|
if ($key =~ /Автор/) { |
|
&UpdateQuestion($dbh, $QuestionId, "Authors", $value); |
|
next; |
|
} |
|
|
|
|
|
if ($key =~ /Источник/) { |
|
&UpdateQuestion($dbh, $QuestionId, "Sources", $value); |
|
next; |
|
} |
|
|
|
|
|
if ($key =~ /Комментари/) { |
if ($key =~ /Комментари/) { |
&UpdateQuestion($dbh, $QuestionId, "Comments", $value); |
&UpdateQuestion($dbh, $QuestionId, "Comments", $value); |
next; |
next; |
} |
} |
|
|
|
my @Fields = grep { $key =~ /$_/ } keys %QuestionFields; |
|
|
if ($key =~ /URL/ || $key =~ /Ссылка/) { |
if (scalar @Fields) { |
&UpdateTournament($dbh, $TournamentId, "URL", $value); |
my $word = shift @Fields; |
next; |
my $field = $QuestionFields{$word}; |
} |
if ($QuestionId) { |
|
&UpdateQuestion($dbh, $QuestionId, $field, $value); |
|
} elsif ($TourId) { |
if ($key =~ /Копирайт/) { |
$QuestionDefaults{$field}=$value; |
&UpdateTournament($dbh, $TournamentId, "Copyright", $value); |
} else { |
next; |
$QuestionGlobalDefaults{$field}=$value; |
} |
} |
|
|
|
|
if ($key =~ /Инфо/) { |
|
&UpdateTournament($dbh, $TournamentId, "Info", $value); |
|
next; |
next; |
} |
} |
|
|
|
|
if ($key =~ /Редактор/) { |
@Fields = grep { $key =~ /$_/ } keys %TourFields; |
&UpdateTournament($dbh, $TournamentId, "Editors", $value); |
|
next; |
|
} |
|
|
|
|
|
if ($key =~ /Обработан/) { |
if (scalar @Fields) { |
&UpdateTournament($dbh, $TournamentId, "EnteredBy", $value); |
my $word = shift @Fields; |
next; |
my $field = $TourFields{$word}; |
} |
if ($QuestionId) { |
|
print STDERR "ОШИБКА: $key $value недопустимы после", |
if ($key =~ /Дата/) { |
" начала вопросов\n"; |
if ($TourId) { |
} elsif ($TourId) { |
&UpdateTournament($dbh, $TourId, "PlayedAt", $value); |
&UpdateTournament($dbh, $TourId, $field, $value); |
} else { |
} else { |
&UpdateTournament($dbh, $TournamentId, "PlayedAt", $value); |
&UpdateTournament($dbh, $TournamentId, $field, $value); |
|
$TourDefaults{$field}=$value; |
} |
} |
next; |
next; |
} |
} |
|
|
|
|
# |
# |
# If we are here, something got wrong! |
# If we are here, something got wrong! |