Jump to content

Talk:List of United States representatives from Maine

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Conversion script

[edit]

I used this script to convert between the list I had copied in here before and the wikitable version. It's probably not the best I could have done, but I'm pasting it here in case anyone finds it useful.--SarekOfVulcan (talk) 15:56, 18 October 2008 (UTC)[reply]

my $infilename = "MaineReps.txt";
my $outfilename = "MaineRepsTable.txt";

open my $INFILE, '<', $infilename or die "Can't open input file: $!";
open my $OUTFILE, '>', $outfilename or die "Can't open output file: $!";

print $OUTFILE qq
	/{| class=\"wikitable\"
! Congress
! Name
! District
! Party
! Residence
! Occupation
/;

my %replist = {};

while (my $line = <$INFILE>) {
	chomp($line);

	my $wordchar = qr{[A-Za-z0-9.\'\&\(\)\/\,]};
	my $matchtoken = qr{$wordchar+(\s$wordchar+)*};
	
	print $OUTFILE "|-\n";

	print $OUTFILE "| " ;
	$lasttoken = $1;
	$line =~ /^\*(\d\d\d?\w\w\, \d{4})\s+.*/;
	if ($1 ne $lasttoken) {
		$congress = $1;
		print $OUTFILE $congress;
	}
	print $OUTFILE "\n" ;
	
	$line =~ /^\*($congress\s+|\t)($matchtoken)\s\s+.*/;
	my $rep = $2;
	$rep =~ /^([A-Za-z0-9\.\,\'\s]+)(\([^\)]+\).*)?/;
	if ($replist{$1}) {
		print $OUTFILE "| " . $rep . "\n";
	} else {
		$replist{$1} = true;
		print $OUTFILE "| [[" . $1 . "]] " . $2 . "\n";
	}
	
	$line =~ /.*\t(\d+)\s.*/; # $rep
	my $district = $1;
	print $OUTFILE "| " . $district . "\n";
	
	$line =~ /.*$district\s*\t($matchtoken)\s\s+.*/;
	my $party = $1;
	print $OUTFILE "| " . $party . "\n";
	
	$line =~ /.*$party\s*\t($matchtoken)\s\s+.*/;
	my $city = $1;
	print $OUTFILE "| " . $city . "\n";

	$line =~ /.*$city\s*\t($matchtoken)(\s*)$/;
	my $occupation = $1;
	print $OUTFILE "| " . $occupation . "\n";

}
print $OUTFILE "|}";