Created
April 10, 2009 02:47
-
-
Save lopnor/92904 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; | |
use charnames ':full'; | |
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$//; | |
$alphabet =~ s/\N{LATIN SMALL LETTER O WITH MACRON}/o/g; | |
$alphabet =~ s/\N{LATIN CAPITAL LETTER O WITH MACRON}/O/g; | |
$pref->{alphabet} = $alphabet; | |
warn $alphabet; | |
} | |
} | |
sleep 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment