#!/usr/bin/perl # domains2map.pl - plot a list of Internet domains on a Google map # Eric Lease Morgan # March 23, 2011 - first investigations # March 24, 2011 - changed radius of circles and added markers # configure use constant CODE4LIB => './etc/code4lib.txt'; use constant NGC4LIB => './etc/ngc4lib.txt'; use constant USABILITY => './etc/usability.txt'; use constant GEOCITIES => './etc/GeoLiteCity.dat'; # include use Geo::IP; use strict; # sanity check my $list = $ARGV[ 0 ]; if ( ! $list ) { &usage } # initalize my $gi = Geo::IP->open( GEOCITIES, GEOIP_STANDARD); my %count = (); my %domains = (); my $index = 0; my $addresses = ''; my $color = ''; # map the list to a file and color if ( $list eq 'Code4Lib' ) { $addresses = CODE4LIB; $color = "#FF0000" } elsif ( $list eq 'NGC4Lib' ) { $addresses = NGC4LIB; $color = "#0000FF" } elsif ( $list eq 'Usability4Lib' ) { $addresses = USABILITY; $color = "#FFFF00" } else { &usage } # process each domain in a list open INPUT, " < $addresses" or die "Can't open $addresses: $!\n"; while ( ) { # initialize geo-location record chop; my $record = $gi->record_by_name( $_ ); # build a "database" of domains, counts, and geo-locations if ( $record ) { $count{ $_ }++; $domains{ $_ } = [( $count{ $_ }, $record->latitude, $record->longitude )]; } # short-circuit the process for debugging purposes #$index++; #last if ( $index > 100 ); } close INPUT; # process each "record" in the "database" to create javascript objects my $citymap = ''; my $markers = ''; foreach my $domain ( keys %domains ) { my $count = $domains{ $domain }[ 0 ]; my $lat = $domains{ $domain }[ 1 ]; my $lng = $domains{ $domain }[ 2 ]; $citymap .= " citymap['$domain'] = {\n"; $citymap .= " center: new google.maps.LatLng($lat, $lng),\n"; $citymap .= " population: $count\n"; $citymap .= " }\n"; $markers .= "var marker = new google.maps.Marker({\n"; $markers .= " position: new google.maps.LatLng( $lat, $lng),\n"; $markers .= " map: map,\n"; $markers .= " title:" . qq("$domain: $count subscribers") . "});\n"; }; # output an html file with substitutions my $html = &template; $html =~ s/##CITYMAP##/$citymap/; $html =~ s/##MARKERS##/$markers/; $html =~ s/##LIST##/$list/g; $html =~ s/##COLOR##/$color/g; print $html; # done exit; sub usage { print "Usage: $0: \n"; exit; } sub template { return < Where in the world are the subscribers to ##LIST##?

Where in the world are the subscribers to ##LIST##?

EOT }