User:Hex/Notes/Lists of elections/Script
Appearance
- What have I become
- My sweetest friend
- Everything I make uses Perl in the end.
#!/usr/bin/perl
use warnings;
use strict;
use constant START_YEAR => 1900;
use constant END_YEAR => 2020;
open (my $OUTPUT, '>', 'elections.txt') or die $!;
# global variables because why not!!! yolo
my $isGray = 1;
my $rowCount = 0;
my $rowStyle = '';
sub tableHeader {
print $OUTPUT <<END
{| style="font-size: 80%; border: 0px; padding: 0px" cellspacing="0" cellpadding="5"
END
}
sub rowHeader {
if ($rowCount == 2) {
$rowCount = 0;
$isGray = !$isGray;
}
print $OUTPUT <<END;
|- @{[ $isGray ? 'style="background: #eee"' : '' ]}
END
$rowCount++;
}
sub linkRow {
my $year = shift;
rowHeader();
print $OUTPUT <<END;
| '''Link'''
| [[$year election]]
| [[$year elections]]
| [[Election $year]]
| [[Elections $year]]
| [[Elections in $year]]
| [[Electoral calendar $year]]
END
}
sub targetRow {
my $year = shift;
rowHeader();
print $OUTPUT <<END;
| '''Target'''
| [[{{subst:#invoke:redirect|main|$year election}}]]
| [[{{subst:#invoke:redirect|main|$year elections}}]]
| [[{{subst:#invoke:redirect|main|Election $year}}]]
| [[{{subst:#invoke:redirect|main|Elections $year}}]]
| [[{{subst:#invoke:redirect|main|Elections in $year}}]]
| [[{{subst:#invoke:redirect|main|Electoral calendar $year}}]]
END
}
sub tableFooter {
print $OUTPUT "|}\n";
}
# ----------------------------------------------------------------------------
print $OUTPUT <<END;
== What titles link to what annual election lists? ==
See [[/Script]] for how this was generated.
END
tableHeader();
for (START_YEAR .. END_YEAR) {
linkRow($_);
targetRow($_);
}
tableFooter();