3 # this will break when megapop changes the URL or format of their listing page.
4 # that's stupid. perhaps they can provide a machine-readable listing?
8 use FS::UID qw(adminsuidsetup);
11 my $url = "http://www.megapop.com/location.htm";
13 my $user = shift or die &usage;
14 adminsuidsetup($user);
16 my %state2usps = &state2usps;
17 $state2usps{'WASHINGTON STATE'} = 'WA'; #megapop's on crack
18 $state2usps{'CANADA'} = 'CANADA'; #freeside's on crack
20 my $ua = new LWP::UserAgent;
21 my $request = new HTTP::Request('GET', $url);
22 my $response = $ua->request($request);
23 die $response->error_as_HTML unless $response->is_success;
26 foreach $line ( split("\n", $response->content) ) {
27 if ( $line =~ /\W(\w[\w\s]*\w)\s+LOCATIONS/i ) {
28 $usps = $state2usps{uc($1)}
29 or warn "warning: unknown state $1\n";
30 } elsif ( $line =~ /(\d{3})\-(\d{3})\-(\d{4})\s+(\w[\w\s]*\w)/ ) {
31 print "$1 $2 $3 $4 $usps\n";
32 my $svc_acct_pop = new FS::svc_acct_pop ( {
38 my $error = $svc_acct_pop->insert;
44 die "Usage:\n $0 user\n";
50 'AMERICAN SAMOA' => 'AS',
55 'CONNECTICUT' => 'CT',
57 'DISTRICT OF COLUMBIA' => 'DC',
58 'FEDERATED STATES OF MICRONESIA' => 'FM',
71 'MARSHALL ISLANDS' => 'MH',
73 'MASSACHUSETTS' => 'MA',
76 'MISSISSIPPI' => 'MS',
81 'NEW HAMPSHIRE' => 'NH',
85 'NORTH CAROLINA' => 'NC',
86 'NORTH DAKOTA' => 'ND',
87 'NORTHERN MARIANA ISLANDS' => 'MP',
92 'PENNSYLVANIA' => 'PA',
93 'PUERTO RICO' => 'PR',
94 'RHODE ISLAND' => 'RI',
95 'SOUTH CAROLINA' => 'SC',
96 'SOUTH DAKOTA' => 'SD',
101 'VIRGIN ISLANDS' => 'VI',
103 'WASHINGTON' => 'WA',
104 'WEST VIRGINIA' => 'WV',
107 'ARMED FORCES AFRICA' => 'AE',
108 'ARMED FORCES AMERICAS' => 'AA',
109 'ARMED FORCES CANADA' => 'AE',
110 'ARMED FORCES EUROPE' => 'AE',
111 'ARMED FORCES MIDDLE EAST' => 'AE',
112 'ARMED FORCES PACIFIC' => 'AP',