Користувач:Дядько Ігор/Скрипти/Філософ

Матеріал з Вікіпедії — вільної енциклопедії.
Перейти до навігації Перейти до пошуку
#!/usr/bin/perl 


#Зчитування словника 

my %dict = ();
open(DIC, "dict.txt"); 
while ($line = <DIC>)
{
 ($orig, $trans) = split (/=/, $line,2);
  $orig =~ s/^\s+//;
  $orig =~ s/\s+$//;
  $trans =~ s/^\s+//;
  $trans =~ s/\s+$//; 
  $dict{ $orig } = $trans;  
}
close(DIC);

# defaults
$name = "{{subst:PAGENAME}}";

open(FC, "philosopher.txt");

while ($line = <FC>)
{
 if ($line =~ m/^\{\{/)
{
 print "skipping\n";
} 
else 
{
 if ($line =~ m/^\}\}/)
 {
  print "skipping\n";
 } 
 else
 {
  ($tag, $value) = split(/=/,$line,2);
  $tag =~ s/^\|//;
  $tag =~ s/^\s+//;
  $tag =~ s/\s+$//; 
  $value =~ s/^\s+//;
  $value =~ s/\s+$//;
  print "$tag $value \n";
  $region = $value if ($tag eq "region");
  $era =  $value if ($tag eq "era");
  $image = $value if ($tag eq "image_name");
  $imagesize = $value if ($tag eq "image_size");
  $caption = $value if ($tag eq "image_caption");
  $name = $value if ($tag eq "name");
  $birth_date = $value if ($tag eq "birth_date");
  $birth_place = $value if ($tag eq "birth_place");
  $death_date = $value if ($tag eq "death_date");
  $death_place = $value if ($tag eq "death_place");
  $school = $value if ($tag eq "schooltradition");
  $interests = $value if ($tag eq "main_interests");
  $ideas = $value if ($tag eq "notable_ideas");
  $influences = $value if ($tag eq "influences");
  $influenced = $value if ($tag eq "influenced");
  $signature = $value if ($tag eq "signature");
}
}  
} 
close(FC);

# Обробка дат 
@months = ("січня", "лютого", "березня", "квітня", "травня", "червня", "липня", "серпня", "вересня", "жовтня", "листопада", "грудня");
if (($birth_date =~ m/birth date/) || ($birth_date =~ m/Birth date/)  )
{
 ($tag, $year, $month, $day) = split(/\|/,$birth_date,5);
 $mn = @months[$month-1]; 
 $birth_date = "[[$day $mn]] [[$year]]"; 
}

if (($death_date =~ m/death date/) || ($death_date =~ m/Death date/))
{
 ($tag, $year, $month, $day) = split(/\|/,$death_date,5);
 $mn = @months[$month-1]; 
 $death_date = "[[$day $mn]] [[$year]]"; 
}

# Переклад посилань 
while ( my ($key, $value) = each(%dict) ) {
        $region =~ s/$key/$value/;
	$era =~ s/$key/$value/;
	$birth_place =~ s/$key/$value/;
	$death_place =~ s/$key/$value/;
	$school =~ s/$key/$value/;
	$interests =~ s/$key/$value/;
	$ideas =~ s/$key/$value/;
	$influences =~ s/$key/$value/;
	$influenced =~ s/$key/$value/;
    }


print<<EndCard
{{Картка:Філософ
|область           = $region
|ера             = $era
|color            = lightsteelblue
|зображення       =  $image
|розмір_зображення       = $imagesize
|підпис_зображення    =  $caption
|ім'я_при_народженні             =  
|дата_народження        = $birth_date
|місце_народження       = $birth_place
|дата_смерті        = $death_date
|місце_смерті       = $death_place
|причина_смерті       = $death_reason
|школа_традиція = $school
|інтереси   = $interests
|ідеї    = $ideas
|під_впливом       = $influences 
|вплинув_на      = $influenced
|підпис        = $signature
|box_width        = 
}}
EndCard
;