version 1.13, 2000/10/22 04:44:53
|
version 1.21, 2002/01/07 01:32:26
|
Line 70 sub getField {
|
Line 70 sub getField {
|
chomp $key; |
chomp $key; |
if ($key eq 'Дата') { |
if ($key eq 'Дата') { |
$value =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/; |
$value =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/; |
my($month) = $RevMonths{$2} || '000'; |
my($month) = $RevMonths{$2} || '01'; |
$value =~ s/$2/$month/; |
$value =~ s/-(.*)-/-$month-/; |
|
$value =~ s/-00*$/-01/; |
} |
} |
$value = $dbh->quote($value); |
$value = $dbh->quote($value); |
return ($key, $value); |
return ($key, $value); |
} |
} |
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 199 sub GetTours {
|
Line 200 sub GetTours {
|
} |
} |
|
|
sub CreateTour { |
sub CreateTour { |
my ($dbh,$title,$ParentId,$rh_defaults)=@_; |
my ($dbh,$title,$ParentId,$TourNum,$rh_defaults)=@_; |
my $sth = $dbh->prepare("INSERT INTO Tournaments |
my $sth = $dbh->prepare("INSERT INTO Tournaments |
(Title, Type, ParentId) |
(Title, Type, ParentId, Number) |
VALUES ($title, 'Т', $ParentId)"); |
VALUES ($title, 'Т', $ParentId, $TourNum)"); |
$sth->execute; |
$sth->execute; |
my $TourId = $sth->{mysql_insertid}; |
my $TourId = $sth->{mysql_insertid}; |
while (my ($key,$value)=each %$rh_defaults) { |
while (my ($key,$value)=each %$rh_defaults) { |
Line 227 MAIN:
|
Line 228 MAIN:
|
# Inherited fields for a Question |
# Inherited fields for a Question |
# |
# |
my %QuestionFields = ('Тип'=> 'Type', 'Вид'=> 'Type', |
my %QuestionFields = ('Тип'=> 'Type', 'Вид'=> 'Type', |
'Автор' => 'Authors', |
'Автор' => 'Authors', 'Рейтинг'=>'Rating', |
'Источник' => 'Source'); |
'Источник' => 'Sources', |
|
'Тема' => 'Topic'); |
|
|
|
|
my($source); |
my($source); |
Line 237 MAIN:
|
Line 239 MAIN:
|
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 253 MAIN:
|
Line 256 MAIN:
|
print STDERR "Файл: $source, дата: $CreatedAt "; |
print STDERR "Файл: $source, дата: $CreatedAt "; |
my %TourDefaults=('CreatedAt'=>$CreatedAt); |
my %TourDefaults=('CreatedAt'=>$CreatedAt); |
my %QuestionDefaults=(); |
my %QuestionDefaults=(); |
my %QuestionGlobalDefaults=(); |
my %QuestionGlobalDefaults=('Type'=>$dbh->quote('Ч')); |
while (($key, $value) = getField(\*INFD, $dbh)) { |
while (($key, $value) = getField(\*INFD, $dbh)) { |
last if (!$key); |
last if (!$key); |
|
|
Line 281 MAIN:
|
Line 284 MAIN:
|
WHERE Id=$TourId"); |
WHERE Id=$TourId"); |
} |
} |
$qnum = 0; |
$qnum = 0; |
$TourId=CreateTour($dbh,$value,$TournamentId,\%TourDefaults); |
$TourNum++; |
|
$TourId=CreateTour($dbh,$value,$TournamentId,$TourNum, |
|
\%TourDefaults); |
%QuestionDefaults=%QuestionGlobalDefaults; |
%QuestionDefaults=%QuestionGlobalDefaults; |
$QuestionId=0; |
$QuestionId=0; |
next; |
next; |
Line 289 MAIN:
|
Line 294 MAIN:
|
if ($key =~ /Вопрос/) { |
if ($key =~ /Вопрос/) { |
if (!$TourId) { |
if (!$TourId) { |
$qnum = 0; |
$qnum = 0; |
$TourId=CreateTour($dbh,'1',$TournamentId, |
$TourNum++; |
|
$TourId=CreateTour($dbh,'1',$TournamentId,$TourNum, |
\%TourDefaults); |
\%TourDefaults); |
%QuestionDefaults=%QuestionGlobalDefaults; |
%QuestionDefaults=%QuestionGlobalDefaults; |
} |
} |
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}; |
Line 318 MAIN:
|
Line 324 MAIN:
|
next; |
next; |
} |
} |
|
|
my @Fields = grep /$key/, keys %QuestionFields; |
my @Fields = grep { $key =~ /$_/ } keys %QuestionFields; |
|
|
if (scalar @Fields) { |
if (scalar @Fields) { |
my $word = shift @Fields; |
my $word = shift @Fields; |
Line 333 MAIN:
|
Line 339 MAIN:
|
next; |
next; |
} |
} |
|
|
@Fields = grep /$key/, keys %TourFields; |
@Fields = grep { $key =~ /$_/ } keys %TourFields; |
|
|
if (scalar @Fields) { |
if (scalar @Fields) { |
my $word = shift @Fields; |
my $word = shift @Fields; |