User:Polbot/source/statsproblems.pl
# statsproblems.pl
use strict;
use Perlwikipedia;
my $soonest_next_op = time;
print "\nStarting polbot\n" ;
my $pw=Perlwikipedia->new();
#$pw->{debug} = 1;
$pw->{mech}->agent('Bot/WP/EN/Quadell/polbot');
print "Logging in\n";
my $login_status=$pw->login('Polbot','(bot password)');
die "I can't log in." unless ($login_status eq 0);
my %judges;
print "Getting judges.\n";
my $main_wiki = $pw->get_text('Wikipedia:WikiProject United States courts and judges/judgestats');
my @lines = split(/\n/, $main_wiki);
foreach my $line (@lines) {
# Ignore non-listed lines
if ($line =~ /^\| \[\[([^\|]+)\]\] \|\|/) {
my $listed_judge = $1;
$judges{$listed_judge} = $listed_judge;
}
}
print scalar(keys %judges) . " judges\n";
# Get known replacements
my %replacements;
print "Getting known replacements.\n";
my $wiki = $pw->get_text('Wikipedia:WikiProject United States courts and judges/judgestats/known replacements');
my @lines = split(/\n/, $wiki);
foreach my $line (@lines) {
# Ignore non-listed lines
if ($line =~ /^\* \[\[(.*)\]\] should be \[\[(.*)\]\]$/m) {
my $tempfrom = $1;
my $tempto = $2;
$replacements{$tempfrom} = $tempto;
}
}
print scalar(keys %replacements) . " replacements\n";
print "Looking through judges:\n";
foreach my $judgekey (sort keys %judges) {
my $judge = $judgekey;
print "[[$judge]] ";
# check for replacements
if ($replacements{$judgekey}) {
$judges{$judgekey} = $replacements{$judgekey};
print "predefined exception: " . $replacements{$judgekey} . "\n";
} else {
# check for redirect
my $wiki = $pw->get_text($judge);
if ($wiki =~ m/\#\s*redirect\s*\[\[(.*)\]\]/i) {
$judge = $1;
print "rd to [[$judge]], ";
$wiki = $pw->get_text($judge);
}
# is it a judge?
if ($wiki =~ m/\[\[\s*category\s*:\s*(Judges of the United States |United States Supreme Court justices|Chief Justices of the United States)/i) {
print "good.\n";
$judges{$judgekey} = $judge;
} else {
print "WRITING ERROR.\n";
my $tempwiki = $pw->get_text('Wikipedia:WikiProject United States courts and judges/judgestats/problems');
$tempwiki .= "* [[$judgekey]]\n";
$pw->edit('Wikipedia:WikiProject United States courts and judges/judgestats/problems', $tempwiki, "* [[$judgekey]]");
}
}
}
# Replace all
foreach my $judge (sort keys %judges) {
if ($judge ne $judges{$judge}) {
$main_wiki =~ s/\[\[$judge\]\]/[[$judges{$judge}]]/g;
}
}
# Pull down info for those whose seats changed by process of law
$main_wiki =~ s/\n\| ([^\|]*) \|\| ([^\|]*) \|\| ([^\|]* \|\| [^\|]+ \|\| [^\|]+ \|\| [^\|]+ \|\| [^\|]+) \|\| ([^\|]+ \|\| [^\|]+) \|\| assignment to another court ([^\n]*)\n\|\-\n\| \1 \|\| ([^\|]*) \|\| \- \|\| \- \|\| \- \|\| \- \|\| \- \|\| ([^\n]*)\n/\n| $1 || $2 || $3 || $4 || assignment to another court $5\n|-\n| $1 || $6 || $3 || $7\n/sg;
print "\n\nWriting back... ";
$pw->edit('Wikipedia:WikiProject United States courts and judges/judgestats', $main_wiki, "cleanup");
die"done.\n";
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.