User:Polbot/source/make court lists.pl

use strict; use Perlwikipedia;

print "\nStarting polbot\n" ; my $pw=Perlwikipedia->new; $pw->{mech}->agent('Bot/WP/EN/Quadell/polbot');
 * 1) $pw->{debug} = 1;

print "Logging in\n"; my $login_status=$pw->login('Polbot','(bot password)'); die "I can't log in." unless ($login_status eq 0);

my %courts; my @judges = ;

print "Reading master list.\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) { #                judge         court         president     recess_d      nom_d         conf_d        comm_d        senior_d      end_d         end_reason    race          gender if ($line =~ /^\| ([^\|]+) \|\| ([^\|]+) \|\| ([^\|]+) \|\| ([^\|]+) \|\| ([^\|]+) \|\| ([^\|]+) \|\| ([^\|]+) \|\| ([^\|]+) \|\| ([^\|]+) \|\| ([^\|]+) \|\| ([^\|]+) \|\| ([^\|]+)/) { my $judge = $1; my $court = $2; my $president = $3; my $recess_date = $4; my $nominated_date = $5; my $confirmed_date = $6; my $commission_date = $7; my $senior_date = $8; my $end_date = $9; my $end_reason = $10; my $race = $11; my $gender = $12; $courts{$court} = $court; my $temphash; $temphash->{"judge"} = $judge; $temphash->{"court"} = $court; $temphash->{"president"} = $president; $temphash->{"recess_date"} = $recess_date; $temphash->{"nominated_date"} = $nominated_date; $temphash->{"confirmed_date"} = $confirmed_date; $temphash->{"commission_date"} = $commission_date; $temphash->{"senior_date"} = $senior_date; if ($end_date eq "-") {$end_date = "Incumbent";} $temphash->{"end_date"} = $end_date; $temphash->{"end_reason"} = $end_reason; $temphash->{"race"} = $race; $temphash->{"gender"} = $gender; push @judges, $temphash; } }

foreach my $court (sort keys %courts) { print "Making $court hash;"; my $outputpage = "User:Polbot/scrap/$court"; $outputpage =~ s/ /_/g; $outputpage =~ s/[\[\]]//g; my @localarray; my $hasnotes = 0; my $hassenior = 0; foreach my $judge (@judges) { if ($judge->{"court"} eq "$court") { my $temphash; $temphash->{"president"} = $judge->{"president"}; $temphash->{"judge"} = $judge->{"judge"}; if ($judge->{"senior_date"} eq "-") { $temphash->{"end_date"} = fmtdate($judge->{"end_date"}); $temphash->{"senior_date"} = "-"; } else { $hassenior = 1; $temphash->{"end_date"} = fmtdate($judge->{"senior_date"}); $temphash->{"senior_date"} = fmtdate($judge->{"end_date"}); }								if ($judge->{"recess_date"} eq "-") { $temphash->{"start_date"} = fmtdate($judge->{"commission_date"}); } else { $hasnotes = 1; if ($judge->{"commission_date"} eq "-") { $temphash->{"start_date"} = fmtdate($judge->{"recess_date"}). " ";						$temphash->{"end_date"} = "(date)"; } else { $temphash->{"start_date"} = fmtdate($judge->{"recess_date"}). " ";					}				}				$temphash->{"end_reason"} = $judge->{"end_reason"}; push @localarray, $temphash; }		}		if (@localarray) { print " prepping output. "; my $wiki_out = '{| class="sortable wikitable"'. "\n". '|- bgcolor="#ececec"'. "\n|Judge||Appointed by"; $wiki_out .= "||Began active service||Ended active service"; if ($hassenior) { $wiki_out .= "||Ended senior status"; }			$wiki_out .= "||End reason\n"; foreach my $judge (@localarray) { $wiki_out .= "|-\n| ". fmtjudge($judge->{"judge"}); $wiki_out .= " || ". $judge->{"president"}; $wiki_out .= " || ". $judge->{"start_date"}; $wiki_out .= " || ". $judge->{"end_date"}; if ($hassenior) { $wiki_out .= " || ". $judge->{"senior_date"}; }				$wiki_out .= "|| ". $judge->{"end_reason"}. "\n"; }			$wiki_out .= "|}\n"; if ($hasnotes) { $wiki_out .= "\n==Notes==\n\n"; }			$wiki_out =~ s/United States Senate/United States Senate/; $wiki_out =~ s/Recess appointment/Recess appointment/; $wiki_out =~ s/later rejected/later rejected/; print "Writing...\n"; $pw->edit($outputpage, $wiki_out, "Writing auto-generated list of judges"); } else { print " no judges.\n"; } }

print "Done\n";

sub fmtjudge { my $judgein = shift; $judgein =~ s/^\[\[(.*)( \(.*\))\]\]$/$1/; return $judgein; }

sub fmtdate { my $datein = shift; if ($datein =~ m/^(.*) (\d+), (\d+)$/) { my $month = $1; my $day = $2; my $year = $3; if ($month eq "January") {$month = "01"} elsif ($month eq "February") {$month = "02"} elsif ($month eq "March") {$month = "03"} elsif ($month eq "April") {$month = "04"} elsif ($month eq "May") {$month = "05"} elsif ($month eq "June") {$month = "06"} elsif ($month eq "July") {$month = "07"} elsif ($month eq "August") {$month = "08"} elsif ($month eq "September") {$month = "09"} elsif ($month eq "October") {$month = "10"} elsif ($month eq "November") {$month = "11"} elsif ($month eq "December") {$month = "12"} if (length($day) == 1) {$day = "0". $day} $datein = ' '. $year. $month. $day. ' ' . $datein; }	return $datein; }

sub abbrevdist { my $district = shift; # District courts if ($district eq "United States District Court for the Southern District of Alabama") {$district = "S.D. Ala.";} elsif ($district eq "United States District Court for the Northern District of Alabama") {$district = "N.D. Ala.";} elsif ($district eq "United States District Court for the Middle District of Alabama") {$district = "M.D. Ala.";} elsif ($district eq "United States District Court for the District of Alaska") {$district = "D. Alaska";} elsif ($district eq "United States District Court for the District of Arizona") {$district = "D. Ariz.";} elsif ($district eq "United States District Court for the Eastern District of Arkansas") {$district = "E.D. Ark.";} elsif ($district eq "United States District Court for the Western District of Arkansas") {$district = "W.D. Ark.";} elsif ($district eq "United States District Court for the Southern District of California") {$district = "S.D. Cal.";} elsif ($district eq "United States District Court for the Northern District of California") {$district = "N.D. Cal.";} elsif ($district eq "United States District Court for the Eastern District of California") {$district = "E.D. Cal.";} elsif ($district eq "United States District Court for the Central District of California") {$district = "C.D. Cal.";} elsif ($district eq "United States District Court for the District of Colorado") {$district = "D. Colo.";} elsif ($district eq "United States District Court for the District of Connecticut") {$district = "D. Conn.";} elsif ($district eq "United States District Court for the District of Delaware") {$district = "D. Del.";} elsif ($district eq "United States District Court for the District of Columbia") {$district = "D.D.C.";} elsif ($district eq "United States District Court for the Northern District of Florida") {$district = "N.D. Fla.";} elsif ($district eq "United States District Court for the Middle District of Florida") {$district = "M.D. Fla.";} elsif ($district eq "United States District Court for the Southern District of Florida") {$district = "S.D. Fla.";} elsif ($district eq "United States District Court for the Northern District of Georgia") {$district = "N.D. Ga.";} elsif ($district eq "United States District Court for the Middle District of Georgia") {$district = "M.D. Ga.";} elsif ($district eq "United States District Court for the Southern District of Georgia") {$district = "S.D. Ga.";} elsif ($district eq "United States District Court for the District of Hawaii") {$district = "D. Haw.";} elsif ($district eq "United States District Court for the District of Idaho") {$district = "D. Idaho";} elsif ($district eq "United States District Court for the Northern District of Illinois") {$district = "N.D. Ill.";} elsif ($district eq "United States District Court for the Central District of Illinois") {$district = "C.D. Ill.";} elsif ($district eq "United States District Court for the Southern District of Illinois") {$district = "S.D. Ill.";} elsif ($district eq "United States District Court for the Northern District of Indiana") {$district = "N.D. Ind.";} elsif ($district eq "United States District Court for the Southern District of Indiana") {$district = "S.D. Ind.";} elsif ($district eq "United States District Court for the Northern District of Iowa") {$district = "N.D. Iowa";} elsif ($district eq "United States District Court for the Southern District of Iowa") {$district = "S.D. Iowa";} elsif ($district eq "United States District Court for the District of Kansas") {$district = "D. Kan.";} elsif ($district eq "United States District Court for the Eastern District of Kentucky") {$district = "E.D. Ky.";} elsif ($district eq "United States District Court for the Western District of Kentucky") {$district = "W.D. Ky.";} elsif ($district eq "United States District Court for the Eastern District of Louisiana") {$district = "E.D. La.";} elsif ($district eq "United States District Court for the Middle District of Louisiana") {$district = "M.D. La.";} elsif ($district eq "United States District Court for the Western District of Louisiana") {$district = "W.D. La.";} elsif ($district eq "United States District Court for the District of Maine") {$district = "D. Me.";} elsif ($district eq "United States District Court for the District of Maryland") {$district = "D. Md.";} elsif ($district eq "United States District Court for the District of Massachusetts") {$district = "D. Mass.";} elsif ($district eq "United States District Court for the Eastern District of Michigan") {$district = "E.D. Mich.";} elsif ($district eq "United States District Court for the Western District of Michigan") {$district = "W.D. Mich.";} elsif ($district eq "United States District Court for the District of Minnesota") {$district = "D. Minn.";} elsif ($district eq "United States District Court for the Northern District of Mississippi") {$district = "N.D. Miss.";} elsif ($district eq "United States District Court for the Southern District of Mississippi") {$district = "S.D. Miss.";} elsif ($district eq "United States District Court for the Eastern District of Missouri") {$district = "E.D. Mo.";} elsif ($district eq "United States District Court for the Western District of Missouri") {$district = "W.D. Mo.";} elsif ($district eq "United States District Court for the District of Montana") {$district = "D. Mont.";} elsif ($district eq "United States District Court for the District of Nebraska") {$district = "D. Neb.";} elsif ($district eq "United States District Court for the District of Nevada") {$district = "D. Nev.";} elsif ($district eq "United States District Court for the District of New Hampshire") {$district = "D.N.H.";} elsif ($district eq "United States District Court for the District of New Jersey") {$district = "D.N.J.";} elsif ($district eq "United States District Court for the District of New Mexico") {$district = "D.N.M.";} elsif ($district eq "United States District Court for the Eastern District of New York") {$district = "E.D.N.Y.";} elsif ($district eq "United States District Court for the Northern District of New York") {$district = "N.D.N.Y.";} elsif ($district eq "United States District Court for the Southern District of New York") {$district = "S.D.N.Y.";} elsif ($district eq "United States District Court for the Western District of New York") {$district = "W.D.N.Y.";} elsif ($district eq "United States District Court for the Eastern District of North Carolina") {$district = "E.D.N.C.";} elsif ($district eq "United States District Court for the Middle District of North Carolina") {$district = "M.D.N.C.";} elsif ($district eq "United States District Court for the Western District of North Carolina") {$district = "W.D.N.C.";} elsif ($district eq "United States District Court for the District of North Dakota") {$district = "D.N.D.";} elsif ($district eq "United States District Court for the Northern District of Ohio") {$district = "N.D. Ohio";} elsif ($district eq "United States District Court for the Southern District of Ohio") {$district = "S.D. Ohio";} elsif ($district eq "United States District Court for the District of South Carolina") {$district = "D.S.C.";} elsif ($district eq "United States District Court for the District of South Dakota") {$district = "D.S.D.";} elsif ($district eq "United States District Court for the Eastern District of Oklahoma") {$district = "E.D. Okla.";} elsif ($district eq "United States District Court for the Northern District of Oklahoma") {$district = "N.D. Okla.";} elsif ($district eq "United States District Court for the Western District of Oklahoma") {$district = "W.D. Okla.";} elsif ($district eq "United States District Court for the District of Oregon") {$district = "D. Or.";} elsif ($district eq "United States District Court for the Western District of Pennsylvania") {$district = "W.D. Pa.";} elsif ($district eq "United States District Court for the Eastern District of Pennsylvania") {$district = "E.D. Pa.";} elsif ($district eq "United States District Court for the Middle District of Pennsylvania") {$district = "M.D. Pa.";} elsif ($district eq "United States District Court for the District of Puerto Rico") {$district = "D.P.R.";} elsif ($district eq "United States District Court for the District of Rhode Island") {$district = "D.R.I.";} elsif ($district eq "United States District Court for the Western District of Tennessee") {$district = "W.D. Tenn.";} elsif ($district eq "United States District Court for the Eastern District of Tennessee") {$district = "E.D. Tenn.";} elsif ($district eq "United States District Court for the Middle District of Tennessee") {$district = "M.D. Tenn.";} elsif ($district eq "United States District Court for the Eastern District of Texas") {$district = "E.D. Tex.";} elsif ($district eq "United States District Court for the Northern District of Texas") {$district = "N.D. Tex.";} elsif ($district eq "United States District Court for the Southern District of Texas") {$district = "S.D. Tex.";} elsif ($district eq "United States District Court for the Western District of Texas") {$district = "W.D. Tex.";} elsif ($district eq "United States District Court for the District of Utah") {$district = "D. Utah";} elsif ($district eq "United States District Court for the District of Vermont") {$district = "D. Vt.";} elsif ($district eq "United States District Court for the Western District of Virginia") {$district = "W.D. Va.";} elsif ($district eq "United States District Court for the Eastern District of Virginia") {$district = "E.D. Va.";} elsif ($district eq "United States District Court for the Western District of Washington") {$district = "W.D. Wash.";} elsif ($district eq "United States District Court for the Eastern District of Washington") {$district = "E.D. Wash.";} elsif ($district eq "United States District Court for the Northern District of West Virginia") {$district = "N.D.W.Va.";} elsif ($district eq "United States District Court for the Southern District of West Virginia") {$district = "S.D.W.Va.";} elsif ($district eq "United States District Court for the Western District of Wisconsin") {$district = "W.D. Wis.";} elsif ($district eq "United States District Court for the Eastern District of Wisconsin") {$district = "E.D. Wis.";} elsif ($district eq "United States District Court for the District of Wyoming") {$district = "D. Wyo.";} elsif ($district eq "United States District Court for the Canal Zone") {$district = "D.C.Z.";} elsif ($district eq "District Court of Guam") {$district = "D. Guam";} elsif ($district eq "United States District Court for the District of Puerto Rico") {$district = "D.P.R.";} elsif ($district eq "District Court of the Virgin Islands") {$district = "D.V.I.";} # Obsolete district courts elsif ($district eq "United States District Court for the District of Alabama") {$district = "D. Ala.";} elsif ($district eq "United States District Court for the District of Arkansas") {$district = "D. Ark.";} elsif ($district eq "United States District Court for the District of California") {$district = "D. Cal.";} elsif ($district eq "United States District Court for the District of Florida") {$district = "D. Fla.";} elsif ($district eq "United States District Court for the District of Georgia") {$district = "D. Ga.";} elsif ($district eq "United States District Court for the District of Illinois") {$district = "D. Ill.";} elsif ($district eq "United States District Court for the Eastern District of Illinois") {$district = "E.D. Ill.";} elsif ($district eq "United States District Court for the District of Iowa") {$district = "D. Iowa.";} elsif ($district eq "United States District Court for the District of Louisiana") {$district = "D. La.";} elsif ($district eq "United States District Court for the District of Michigan") {$district = "D. Mich.";} elsif ($district eq "United States District Court for the District of Mississippi") {$district = "D. Miss.";} elsif ($district eq "United States District Court for the District of Missouri") {$district = "D. Mo.";} elsif ($district eq "United States District Court for the Eastern District of New Jersey") {$district = "E.D.N.J.";} elsif ($district eq "United States District Court for the Western District of New Jersey") {$district = "W.D.N.J.";} elsif ($district eq "United States District Court for the District of New York") {$district = "D.N.Y.";} elsif ($district eq "United States District Court for the District of North Carolina") {$district = "D.N.C.";} elsif ($district eq "United States District Court for the District of Ohio") {$district = "D. Ohio.";} elsif ($district eq "United States District Court for the District of Pennsylvania") {$district = "D. Pa.";} elsif ($district eq "United States District Court for the Eastern District of South Carolina") {$district = "E.D.S.C.";} elsif ($district eq "United States District Court for the Western District of South Carolina") {$district = "W.D.S.C.";} elsif ($district eq "United States District Court for the District of Tennessee") {$district = "D. Tenn.";} elsif ($district eq "United States District Court for the District of Texas") {$district = "D. Tex.";} elsif ($district eq "United States District Court for the District of Virginia") {$district = "D. Va.";} elsif ($district eq "United States District Court for the District of Washington") {$district = "D. Wash.";} elsif ($district eq "United States District Court for the District of West Virginia") {$district = "D.W.Va.";} elsif ($district eq "United States District Court for the District of Wisconsin") {$district = "D. Wis.";} elsif ($district eq "United States District Court for the District of Kentucky") {$district = "D. Ky.";} elsif ($district eq "United States District Court for the District of Indiana") {$district = "D. In.";} # Appelate courts elsif ($district eq "United States Court of Appeals for the First Circuit") {$district = "First";} elsif ($district eq "United States Court of Appeals for the Second Circuit") {$district = "Second";} elsif ($district eq "United States Court of Appeals for the Third Circuit") {$district = "Third";} elsif ($district eq "United States Court of Appeals for the Fourth Circuit") {$district = "Fourth";} elsif ($district eq "United States Court of Appeals for the Fifth Circuit") {$district = "Fifth";} elsif ($district eq "United States Court of Appeals for the Sixth Circuit") {$district = "Sixth";} elsif ($district eq "United States Court of Appeals for the Seventh Circuit") {$district = "Seventh";} elsif ($district eq "United States Court of Appeals for the Eighth Circuit") {$district = "Eighth";} elsif ($district eq "United States Court of Appeals for the Ninth Circuit") {$district = "Ninth";} elsif ($district eq "United States Court of Appeals for the Tenth Circuit") {$district = "Tenth";} elsif ($district eq "United States Court of Appeals for the Eleventh Circuit") {$district = "Eleventh";} elsif ($district eq "United States Court of Appeals for the D.C. Circuit") {$district = "D.C. Cir.";} elsif ($district eq "United States Court of Appeals for the Federal Circuit") {$district = "Fed. Cir.";}

# Circuit courts elsif ($district =~ /\[\[United States circuit court\]\] for the (.*) Circuit/) {$district = $1;} return $district; }