Користувач:Дядько Ігор/Письменник

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

Необхідні файли "writer.txt" - вихідний текст, "dict.txt" - словник.

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

#!/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);

open(FC, "writer.txt");

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

while ($line = <FC>)
{
 if ($line =~ m/^\{\{/)
{
 print "skipping\n";
} 
else 
{
 if ($line =~ m/^\}\}/)
 {
  print "skipping\n";
 } 
 else
 {
  ($tag, $field) = split(/=/,$line,2);
  $tag =~ s/^\|//;
  $tag =~ s/^\s+//;
  $tag =~ s/\s+$//; 
  $field =~ s/^\s+//;
  $field =~ s/\s+$//; 
  print "$tag $field\n";
  $original_name = $field if ($tag eq "name"); 
  $image = $field if ($tag eq "image"); 
  $imagewidth = $field if ($tag eq "imagesize");
  $caption = $field if ($tag eq "caption");
  $pseudo = $field if ($tag eq "pseudonym"); 
  $birth_name = $field if ($tag eq "birthname");
  $birth_date = $field if ($tag eq "birthdate");
  $birth_place = $field if ($tag eq "birthplace");
  $death_date = $field if ($tag eq "deathdate");
  $death_place = $field if ($tag eq "deathplace"); 
  $nationality = $field if ($tag eq "nationality");
  $awards = $field if ($tag eq "awards");
  $website = $field if ($tag eq "website");
  $period = $field if ($tag eq "period");
}
}  
} 
close(FC);

# defaults 
$language = "[[англійська мова|англійська]]";
$citizenship = "[[США]]";
$nationality = "[[США]]";
$profession = "[[письменник]]";

# Обробка дат 
@months = ("січня", "лютого", "березня", "квітня", "травня", "червня", "липня", "серпня", "вересня", "жовтня", "листопада", "грудня");
if ($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/ )
{
 ($tag, $year, $month, $day) = split(/\|/,$death_date,5);
 $mn = @months[$month-1]; 
 $death_date = "[[$day $mn]] [[$year]]"; 
}

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

print<<EndCard
{{Письменник
| Ім'я                = $name
| Оригінал імені      = $original_name
| Фото                = $image
| Ширина              = $image_width
| Підпис              = $caption
| Ім'я при народженні = $birth_name
| Псевдоніми          = $pseudo
| Дата народження     = $birth_date
| Місце народження    = $birth_place
| Дата смерті         = $death_date
| Місце смерті        = $death_place
| Національність      = $nationality
| Громадянство        = $citizenship
| Мова творів         = $language
| Рід діяльності      = $profession
| Роки активності     = $period
| Напрямок            = $direction
| Жанр                = $genre
| Magnum opus         = $opus
| Ukrcenter           = $ukr_center
| Премії              = $awards
| Сайт                = $website
| Примітки            = $notes
}}

EndCard
;