Skip to content

Instantly share code, notes, and snippets.

@lopnor
Created April 10, 2009 00:34
Show Gist options
  • Save lopnor/92843 to your computer and use it in GitHub Desktop.
Save lopnor/92843 to your computer and use it in GitHub Desktop.
#!/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