added importing doogal data for wards on postcode
This commit is contained in:
parent
9b7d8530b6
commit
c977cf3279
16 changed files with 4947 additions and 1 deletions
44
lib/Pear/LocalLoop/Import/LCCCsv/Postcodes.pm
Normal file
44
lib/Pear/LocalLoop/Import/LCCCsv/Postcodes.pm
Normal file
|
@ -0,0 +1,44 @@
|
|||
package Pear::LocalLoop::Import::LCCCsv::Postcodes;
|
||||
use Moo;
|
||||
|
||||
use Geo::UK::Postcode::Regex;
|
||||
|
||||
extends qw/Pear::LocalLoop::Import::LCCCsv/;
|
||||
|
||||
has '+csv_required_columns' => (
|
||||
builder => sub { return [ qw/
|
||||
postcode
|
||||
ward
|
||||
/ ]},
|
||||
);
|
||||
|
||||
sub import_csv {
|
||||
my ($self) = @_;
|
||||
|
||||
my $rows = $self->csv_data;
|
||||
|
||||
foreach my $row ( @{$rows} ) {
|
||||
$self->_row_to_result($row);
|
||||
}
|
||||
}
|
||||
|
||||
use Devel::Dwarn;
|
||||
sub _row_to_result {
|
||||
my ( $self, $row ) = @_;
|
||||
|
||||
my $postcode_obj = Geo::UK::Postcode::Regex->parse( $row->{postcode} );
|
||||
|
||||
my $ward = $self->schema->resultset('GbWard')->find_or_create(ward => $row->{ward});
|
||||
|
||||
my $postcode_r = $self->schema->resultset('GbPostcode')->find({
|
||||
outcode => $postcode_obj->{outcode},
|
||||
incode => $postcode_obj->{incode},
|
||||
});
|
||||
|
||||
return unless $postcode_r;
|
||||
return if $postcode_r->ward;
|
||||
|
||||
$postcode_r->update({ ward_id => $ward->id });
|
||||
}
|
||||
|
||||
1;
|
Reference in a new issue