Користувач:Дядько Ігор/Архіватор
Код, архіватора, ще не повністю автоматичний.
#!/usr/bin/perl
$page_name = "Вікіпедія:Кнайпа \(різне\)";
open(LO, "page_to_archive");
$n = 0;
while ( $lines[$n] = <LO>)
{
$n++;
}
$n_topic = 0;
for ($n = 0; $n < @lines; $n++)
{
if ( $lines[$n] =~ m/===(.*)===/)
{
next;
}
if ( $lines[$n] =~ m/==(.*)==/)
{
$entry = $1;
if ($entry =~ m/(.*)\[\[(.*)\|(.*)\]\](.*)/)
{
$entry = "$1 $3 $4";
$entry =~ s/^\s+//;
$entry =~ s/\s+$//;
}
if ($entry =~ m/(.*)\[\[(.*)\]\](.*)/)
{
$entry = "$1 $2 $3";
}
$topic_entry[$prev_n_topic] = "$topic_entry[$prev_n_topic] ($min_time_s - $max_time_s)" if $n_topic > 0;
$entry =~ s/^\s+//;
while ($entry =~ s/[:\/]/ /g) {};
$topic_entry[$n_topic] = $entry;
$topic_line[$n_topic] = $n;
$n_topic++;
$max_time = 0;
$min_time = 20200101;
}
if ( $lines[$n] =~ m/(.*):(.*)\, (.*) \(UTC\)/)
{
$date = $3;
($day, $month, $year) = split(/ /, $date);
$month_n = '01' if ($month eq 'січня');
$month_n = '02' if ($month eq 'лютого');
$month_n = '03' if ($month eq 'березня');
$month_n = '04' if ($month eq 'квітня');
$month_n = '05' if ($month eq 'травня');
$month_n = '06' if ($month eq 'червня');
$month_n = '07' if ($month eq 'липня');
$month_n = '08' if ($month eq 'серпня');
$month_n = '09' if ($month eq 'вересня');
$month_n = '10' if ($month eq 'жовтня');
$month_n = '11' if ($month eq 'листопада');
$month_n = '12' if ($month eq 'грудня');
$day_n = $day;
$day_n = "0$day" if $day < 10;
$timest = "$year$month_n$day_n";
$timest_s = "$day_n\.$month_n\.$year";
if ($timest < $min_time)
{
$min_time = $timest;
$min_time_s = $timest_s;
}
if ($timest > $max_time)
{
$max_time = $timest ;
$max_time_s = $timest_s;
}
$prev_n_topic = $n_topic -1;
}
}
for ($n_topic = 0; $n_topic < @topic_entry; $n_topic++)
{
print "*\[\[$page_name\/$topic_entry[$n_topic]\|$topic_entry[$n_topic]\]\]\n";
}
$n_topic = 0;
for ($n = 0; $n < @lines; $n++)
{
if ( $lines[$n] =~ m/===(.*)===/)
{
print $lines[$n];
next;
}
if ( $lines[$n] =~ m/==(.*)==/)
{
print "END\n" if $n_topic > 0;
print "START\n";
print "'''$page_name\/$topic_entry[$n_topic]'''\n";
$n_topic++;
next;
}
print $lines[$n];
}