Created
April 10, 2009 00:34
-
-
Save lopnor/92843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# get_alphabets.pl | |
use strict; | |
use warnings; | |
use lib 'lib'; | |
use Geography::JapanesePrefectures; | |
use WebService::Simple; | |
use Data::Dumper; | |
my $api = WebService::Simple->new( | |
base_url => 'http://maps.google.com/maps/geo', | |
response_parser => 'XML::LibXML', | |
param => { | |
output => 'xml', | |
} | |
); | |
my $infos = Geography::JapanesePrefectures->prefectures_infos(); | |
for my $pref (@$infos) { | |
my $res = $api->get({q => $pref->{name}}); | |
if ($res->is_success) { | |
my $geo = eval { $res->parse_response->documentElement }; | |
if ($geo && $geo->getElementsByTagName('code')->shift->textContent eq '200') { | |
my $alphabet = $geo->getElementsByTagName('AdministrativeAreaName')->shift->textContent; | |
$alphabet =~ s/ Prefecture$//; | |
$pref->{alphabet} = $alphabet; | |
} | |
} | |
sleep 1; | |
} | |
warn Dumper $infos; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment