diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/send-reports | 10 | ||||
-rwxr-xr-x | bin/update-areas | 46 |
2 files changed, 51 insertions, 5 deletions
diff --git a/bin/send-reports b/bin/send-reports index 4d5546a55..222d99318 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -6,7 +6,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # -# $Id: send-reports,v 1.45 2007-08-02 11:44:59 matthew Exp $ +# $Id: send-reports,v 1.46 2007-08-24 12:27:30 matthew Exp $ use strict; require 5.8.0; @@ -161,8 +161,8 @@ if ($verbose) { # Will do for now :) sub essex_contact { my ($E, $N) = @_; - my $district = mySociety::MaPit::get_voting_area_by_location_en($E, $N, 'polygon', 'DIS'); - $district = $district->[0]; + my $district = mySociety::MaPit::get_voting_areas_by_location({easting=>$E, northing=>$N}, 'polygon', 'DIS'); + ($district) = keys %$district; my $email; $email = 'eastarea' if $district == 2315 || $district == 2312; $email = 'midarea' if $district == 2317 || $district == 2314 || $district == 2316; @@ -175,8 +175,8 @@ sub essex_contact { # Notts has different contact addresses depending upon the district sub notts_contact { my ($E, $N) = @_; - my $district = mySociety::MaPit::get_voting_area_by_location_en($E, $N, 'polygon', 'DIS'); - $district = $district->[0]; + my $district = mySociety::MaPit::get_voting_areas_by_location({easting=>$E, northing=>$N}, 'polygon', 'DIS'); + ($district) = keys %$district; my $email; $email = 'cshighsouth.en' if $district == 2411 || $district == 2412 || $district == 2415; $email = 'etwall' if $district == 2413 || $district == 2416; diff --git a/bin/update-areas b/bin/update-areas new file mode 100755 index 000000000..b161d039b --- /dev/null +++ b/bin/update-areas @@ -0,0 +1,46 @@ +#!/usr/bin/perl -w + +# update-areas: +# One-off script to populate the areas column of the problem table +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org +# +# $Id: update-areas,v 1.1 2007-08-24 12:27:30 matthew Exp $ + +use strict; +require 5.8.0; + +# Horrible boilerplate to set up appropriate library paths. +use FindBin; +use lib "$FindBin::Bin/../perllib"; +use lib "$FindBin::Bin/../../perllib"; + +use mySociety::Config; +use mySociety::DBHandle qw(dbh select_all); +use mySociety::MaPit; +use mySociety::VotingArea; + +BEGIN { + mySociety::Config::set_file("$FindBin::Bin/../conf/general"); + mySociety::DBHandle::configure( + Name => mySociety::Config::get('BCI_DB_NAME'), + User => mySociety::Config::get('BCI_DB_USER'), + Password => mySociety::Config::get('BCI_DB_PASS'), + Host => mySociety::Config::get('BCI_DB_HOST', undef), + Port => mySociety::Config::get('BCI_DB_PORT', undef) + ); +} + +print "Fetching problems...\n"; +my $ids = select_all("select id, easting, northing from problem where areas=''"); +print "Updating areas...\n"; +my $c = 0; +foreach (@$ids) { + my $areas = mySociety::MaPit::get_voting_areas_by_location({easting=>$_->{easting}, northing=>$_->{northing}}, 'polygon'); + $areas = ',' . join(',', sort keys %$areas) . ','; + dbh()->do('update problem set areas=? where id=?', {}, $areas, $_->{id}); + dbh()->commit(); + print "Done: " . (++$c) . "/" . @$ids . "\n"; +} + |