Jump to content

User:Polbot/source/make court lists.pl

From Wikipedia, the free encyclopedia
use strict;
use Perlwikipedia;

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 %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"}) . "<ref>Recess appointment; the United States Senate later rejected the appointment.</ref>";
						$temphash->{"end_date"} = "(date)";
					} else {
						$temphash->{"start_date"} = fmtdate($judge->{"recess_date"}) . "<ref>Recess appointment; formally nominated on " . $judge->{"nominated_date"} . ", confirmed by the United States Senate on " . $judge->{"confirmed_date"} . ", and received commission on " . $judge->{"commission_date"} . ".</ref>";
					}
				}
				$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<br>service'''||'''Ended active<br>service'''";
			if ($hassenior) {
				$wiki_out .= "||'''Ended senior<br>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{{reflist}}\n";
			}
			$wiki_out =~ s/United States Senate/[[United States Senate]]/;
			$wiki_out =~ s/Recess appointment/[[Recess appointment]]/;
			$wiki_out =~ s/later rejected/later [[Rejected recess appointments to United States federal courts|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$2|$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 = '<span style="display:none">' . $year . $month . $day . '</span>' . $datein;
	}
	return $datein;
}

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

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