User:Polbot/source/List politicians.pl

use Perlwikipedia; use strict;

my @states = ("Alaska", "Alabama", "Arkansas", "Arizona", "California", "Colorado", "Connecticut", "Deleware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Montana", "Missouri", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming");

my $pw=Perlwikipedia->new; $pw->{mech}->agent('Bot/WP/EN/Quadell/polbot');

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

my %pols = ;

print "\nReading todo file\n"; my $todo_list = $pw->get_text('User:Polbot/altnames/todo'); my @lines = split(/\n/, $todo_list); foreach my $line (@lines) { if ($line =~ m/^\* \[\[([^]]*)\]\]\*(.*)$/) { $pols{$1} = $2; } }

&process_cats ("Category:Continental Congressmen", "Continental Congressman"); &deeply_process_cats ("Category:United States presidential candidates", "U.S. presidential candidate"); &process_cats ("Category:Confederate States Cabinet members", "cabinet member of the CSA"); &process_cats ("Category:Deputies and delegates of the Provisional Confederate Congress", "Confederate congressional delegate"); &deeply_process_cats ("Category:State supreme court judges in the United States", "state supreme court justice"); &deeply_process_cats ("Category:United States court of appeals judges", "U.S. court of appeals judge");

foreach my $state (@states) { &process_cats ("Category:$state State Senators", "$state state senator"); &process_cats ("Category:Members of the $state House of Representatives", "$state state representative"); }

my $wiki_out = ''; foreach my $name (sort keys %pols) { if ($name !~ m/[^\x20-\x7E]/) { $wiki_out .= "* $name*". $pols{$name}. "\n"; } }
 * 1) Now write to ToDo

$pw->edit('User:Polbot/altnames/todo', $wiki_out, "Creation of full list");
 * 1) print "It's " . length ($wiki_out) . " long.\n";


 * 1) print $wiki_out;

sub process_cats { my $category_name = shift; my $jobtitle = shift; print "working on $category_name\n";

my @these_pols = $pw->get_pages_in_category($category_name); foreach my $catmember (@these_pols) { if ($catmember !~ m/^(List of|Category|Template|United States)/) { if (! $pols{$catmember} ) { $pols{$catmember} = $jobtitle; }		}	} }

sub deeply_process_cats { my $category_name = shift; my $jobtitle = shift; print "working on $category_name (and subcats)\n";

my @these_pols = $pw->get_all_pages_in_category($category_name); foreach my $catmember (@these_pols) { if ($catmember !~ m/^(List of|Category|Template|United States)/) { if (! $pols{$catmember} ) { $pols{$catmember} = $jobtitle; }		}	} }