#!/usr/bin/perl -w # bm.pl - by dual # cli for bell's mind # usage: perl bm.pl -[nxch] use strict; use LWP; use HTML::TokeParser::Simple; help() unless defined(my $choice = shift); help() unless defined(my $input = shift); if ($choice =~ /-n/i) { npa(); } elsif ($choice =~ /-x/i) { nxx(); } elsif ($choice =~ /-c/i) { clli(); } elsif ($choice =~ /-h/i) { help(); } else { print "Choose -n, -x, -c, or -h for help...\n"; exit; } exit; # ---------- Provide assistance ---------- # sub help { print < -n = NPA search -x = NPA-NXX search -c = CLLI search -h = This help message EOF exit; } # ---------------------------------------- # # ---------- Retrieve NPA data ---------- # sub npa { if ($input !~ /\d{3}/) { print "Enter area code as NPA...\n"; exit; } my $browser = LWP::UserAgent->new; $browser->env_proxy(); my $response = $browser->get( "http://bellsmind.net/Engine/legacy/BellsMindParseNPA.php?SearchType=NPA&NPA=$input" ); die "Error: ", $response->status_line unless $response->is_success; my $content = $response->content; print "Results for NPA $input:\n\n"; print " "; my $count = 0; while ($content =~ /(\d{3})<\/A>/gs) { $1 != '211' ? print "$1 " : last; $count++; if ($count == 15) { print "\n "; $count = 0; } } print "\n"; } # -------------------------------------- # # ---------- Retrieve NPA-NXX data ---------- # sub nxx { if ($input !~ /\d{3}-\d{3}/) { print "Enter area code and exchange as NPA-NXX...\n"; exit; } my($npa, $nxx) = split(/-/, $input); my $browser = LWP::UserAgent->new; $browser->env_proxy(); my $response = $browser->get( "http://bellsmind.net/Engine/legacy/BellsMindParseExtended.php?SearchType=NPANXX&NPA=$npa&NXX=$nxx" ); die "Error: ", $response->status_line unless $response->is_success; my $output = $response->content; my $stream = HTML::TokeParser::Simple->new(\$output); my $count1 = 0; my $count2 = 0; my $spltrcs; while (my $token = $stream->get_token) { if ($token->is_text) { my $text = $token->as_is; if ($text =~ /Location/) {print "$text\t";} elsif ($text =~ /Address/) {print "$text\t";} elsif ($text =~ /Use code/) {print "$text\t";} elsif ($text =~ /OCN/) {print "$text\t\t";} elsif ($text =~ /Company/) {print "$text\t";} elsif ($text =~ /Local RC/) {print "$text\t";} elsif ($text =~ /Switch RCs/) {print "$text\t";} elsif ($text =~ /CLLI/) {print "$text\t\t";} elsif ($text =~ /IG/) {print "$text\t\t";} elsif ($text =~ /Switch type/) {print "$text\t";} elsif ($text =~ /Also serves/) {print "$text\t";} elsif ($text =~ /Scanned/) {last;} elsif ($text =~ /\[.+\]/) { my @rcs = split(/\]\s\[/, $text); for $spltrcs(@rcs) { print "$spltrcs "; $count1++; if ($count1 == 5) { print "\n\t\t"; $count1 = 0; } } } elsif ($text =~ /\d{3}-\d{3}/) { print $text; $count2++; if ($count2 == 7) { print "\n\t\t\b"; $count2 = 1; } } else {print $text;} } } } # ------------------------------------------- # # ---------- Retrieve CLLI data ---------- # sub clli { if ($input =~ /[^A-Z0-9]/) { print "CLLI must be all caps...\n"; exit; } my $browser = LWP::UserAgent->new; $browser->env_proxy(); my $response = $browser->get( "http://bellsmind.net/Engine/legacy/BellsMindParseExtended.php?SearchType=CLLI&CLLI=$input" ); die "Error: ", $response->status_line unless $response->is_success; my $output = $response->content; my $stream = HTML::TokeParser::Simple->new(\$output); my $count1 = 0; my $count2 = 0; my $spltrcs; while (my $token = $stream->get_token) { if ($token->is_text) { my $text = $token->as_is; if ($text =~ /Location/) {print "$text\t";} elsif ($text =~ /Address/) {print "$text\t";} elsif ($text =~ /Use code/) {print "$text\t";} elsif ($text =~ /OCN/) {print "$text\t\t";} elsif ($text =~ /Company/) {print "$text\t";} elsif ($text =~ /Local RC/) {print "$text\t";} elsif ($text =~ /Switch RCs/) {print "$text\t";} elsif ($text =~ /CLLI/) {print "$text\t\t";} elsif ($text =~ /IG/) {print "$text\t\t";} elsif ($text =~ /Switch type/) {print "$text\t";} elsif ($text =~ /Also serves/) {print "$text\t";} elsif ($text =~ /Scanned/) {last;} elsif ($text =~ /\[.+\]/) { my @rcs = split(/\]\s\[/, $text); for $spltrcs(@rcs) { print "$spltrcs "; $count1++; if ($count1 == 5) { print "\n\t\t"; $count1 = 0; } } } elsif ($text =~ /\d{3}-\d{3}/) { print $text; $count2++; if ($count2 == 7) { print "\n\t\t\b"; $count2 = 1; } } else {print $text;} } } } # ---------------------------------------- #