Added otucode listings for codepoint_open command

This commit is contained in:
Tom Bloor 2017-09-21 15:52:01 +01:00
parent f056199ec1
commit 3e87326265

View file

@ -12,27 +12,37 @@ has usage => sub { shift->extract_usage };
sub run { sub run {
my ( $self, @args ) = @_; my ( $self, @args ) = @_;
getopt \@args,
'o|outcodes=s' => \my @outcodes;
'q|quiet' => \my $quiet_mode;
my $cpo_dir = $self->app->home->child('etc')->child('code-point-open'); my $cpo_dir = $self->app->home->child('etc')->child('code-point-open');
my $zip_file = $cpo_dir->child('codepo_gb.zip')->realpath->to_string; my $zip_file = $cpo_dir->child('codepo_gb.zip')->realpath->to_string;
my $output_dir = $cpo_dir->child('codepo_gb')->realpath->to_string; my $output_dir = $cpo_dir->child('codepo_gb')->realpath->to_string;
unless ( -d $output_dir ) { unless ( -d $output_dir ) {
print "Unzipping code-point-open data\n"; print "Unzipping code-point-open data\n" unless $quiet_mode;
system( 'unzip', '-q', $zip_file, '-d', $output_dir ); system( 'unzip', '-q', $zip_file, '-d', $output_dir );
} }
my $cpo = Geo::UK::Postcode::CodePointOpen->new( path => $output_dir ); my $cpo = Geo::UK::Postcode::CodePointOpen->new( path => $output_dir );
use Devel::Dwarn; use Devel::Dwarn;
my $i = 0; Dwarn \@outcodes;
print 'Importing data for ' . $#outcodes ? join( ' ', @outcodes ) : 'all' . 'outcodes\n'
unless $quiet_mode;
my $i = 0;
my $iter = $cpo->read_iterator( my $iter = $cpo->read_iterator(
outcodes => \@outcodes,
include_lat_long => 1, include_lat_long => 1,
split_postcode => 1, split_postcode => 1,
); );
while ( my $pc = $iter->() ) { while ( my $pc = $iter->() ) {
Dwarn $pc; $i++;
last if $i++ > 10; }
}
Dwarn $i;
} }
=head1 SYNOPSIS =head1 SYNOPSIS
@ -41,7 +51,8 @@ while ( my $pc = $iter->() ) {
Options: Options:
none, for now... -o|--outcodes <outcode> : limit to specified outcodes (can be defined
multiple times)
=cut =cut