From 119774e434f681e17e127988bb367446146451bc Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 21 Sep 2017 15:17:45 +0100 Subject: [PATCH] First pass of codepoint_open importer --- lib/Pear/LocalLoop/Command/codepoint_open.pm | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lib/Pear/LocalLoop/Command/codepoint_open.pm diff --git a/lib/Pear/LocalLoop/Command/codepoint_open.pm b/lib/Pear/LocalLoop/Command/codepoint_open.pm new file mode 100644 index 0000000..3c865e9 --- /dev/null +++ b/lib/Pear/LocalLoop/Command/codepoint_open.pm @@ -0,0 +1,48 @@ +package Pear::LocalLoop::Command::codepoint_open; +use Mojo::Base 'Mojolicious::Command'; + +use Mojo::Util 'getopt'; + +use Geo::UK::Postcode::CodePointOpen; + +has description => 'Manage Codepoint Open Data'; + +has usage => sub { shift->extract_usage }; + +sub run { + my ( $self, @args ) = @_; + + 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 $output_dir = $cpo_dir->child('codepo_gb')->realpath->to_string; + + unless ( -d $output_dir ) { + print "Unzipping code-point-open data\n"; + system( 'unzip', '-q', $zip_file, '-d', $output_dir ); + } + + my $cpo = Geo::UK::Postcode::CodePointOpen->new( path => $output_dir ); + +use Devel::Dwarn; +my $i = 0; + my $iter = $cpo->read_iterator( + include_lat_long => 1, + split_postcode => 1, + ); +while ( my $pc = $iter->() ) { + Dwarn $pc; + last if $i++ > 10; +} +} + +=head1 SYNOPSIS + + Usage: APPLICATION codepoint_open [OPTIONS] + + Options: + + none, for now... + +=cut + +1;