aboutsummaryrefslogtreecommitdiffstats
path: root/bin/send-reports
diff options
context:
space:
mode:
authorEdmund von der Burg <evdb@mysociety.org>2011-04-04 12:24:03 +0100
committerEdmund von der Burg <evdb@mysociety.org>2011-04-04 12:24:03 +0100
commit8fa7e52025478515203b39f3e7afafb829b60731 (patch)
tree295fb14df87abc4577418cfd294931cc51f7c991 /bin/send-reports
parent689e4c3bd7c7c1cb24ecad3b35a57947bfb7945b (diff)
parente591ef105c5996e95f2e7738b324c25b3708f0be (diff)
Merge branch 'master' into migrate_to_catalyst
Conflicts: .gitignore commonlib conf/packages perllib/FixMyStreet/Map.pm templates/website/cobrands/barnet/footer web/confirm.cgi web/css/core.css web/import.cgi web/index.cgi
Diffstat (limited to 'bin/send-reports')
-rwxr-xr-xbin/send-reports40
1 files changed, 36 insertions, 4 deletions
diff --git a/bin/send-reports b/bin/send-reports
index 84bfb1791..8e6d2d178 100755
--- a/bin/send-reports
+++ b/bin/send-reports
@@ -18,6 +18,8 @@ use lib "$FindBin::Bin/../commonlib/perllib";
use Encode;
use Error qw(:try);
use File::Slurp;
+use JSON;
+use LWP::Simple;
use CGI; # Trying awkward kludge
use CronFns;
@@ -97,9 +99,8 @@ foreach my $row (@$unsent) {
$h{fuzzy} = $row->{used_map} ? _('To view a map of the precise location of this issue')
: _('The user could not locate the problem on a map, but to see the area around the location they entered');
$h{closest_address} = '';
- $h{closest_address_machine} = '';
- # If we are in the UK include eastings and northings
+ # If we are in the UK include eastings and northings, and nearest stuff
$h{easting_northing} = '';
if ( mySociety::Config::get('COUNTRY') eq 'GB' ) {
@@ -109,7 +110,10 @@ foreach my $row (@$unsent) {
$h{easting_northing} #
= "Easting: $h{easting}\n\n" #
. "Northing: $h{northing}\n\n";
+
+ $h{closest_address} = find_closest($row, $h{latitude}, $h{longitude});
}
+ $h{closest_address_machine} = $h{closest_address};
my (@to, @recips, $template, $areas_info);
if ($site eq 'emptyhomes') {
@@ -138,7 +142,7 @@ foreach my $row (@$unsent) {
# XXX Needs locks!
my @all_councils = split /,|\|/, $row->{council};
my ($councils, $missing) = $row->{council} =~ /^([\d,]+)(?:\|([\d,]+))?/;
- my @councils = split /,/, $councils;
+ my @councils = split(/,/, $councils);
$areas_info = mySociety::MaPit::call('areas', \@all_councils);
my (@dear, %recips);
my $all_confirmed = 1;
@@ -174,7 +178,7 @@ foreach my $row (@$unsent) {
$template = 'submit-brent' if $row->{council} eq 2488 || $row->{council} eq 2237;
$template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/$template");
- if ($h{category} eq 'Other') {
+ if ($h{category} eq _('Other')) {
$h{category_footer} = _('this type of local problem');
$h{category_line} = '';
} else {
@@ -342,3 +346,31 @@ sub post_easthants_message {
return $return;
}
+sub find_closest {
+ my ($row, $latitude, $longitude) = @_;
+ my $str = '';
+
+ return '' unless $row->{used_map};
+
+ # Get nearest road-type thing from Bing
+ my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?c=en-GB&key=" . mySociety::Config::get('BING_MAPS_API_KEY');
+ my $j = LWP::Simple::get($url);
+ if ($j) {
+ $j = JSON->new->utf8->allow_nonref->decode($j);
+ if ($j->{resourceSets}[0]{resources}[0]{name}) {
+ $str .= "Nearest road to the pin placed on the map (automatically generated by Bing Maps): $j->{resourceSets}[0]{resources}[0]{name}\n\n";
+ }
+ }
+
+ # Get nearest postcode from Matthew's random gazetteer (put in MaPit? Or elsewhere?)
+ $url = "http://gazetteer.dracos.vm.bytemark.co.uk/point/$latitude,$longitude.json";
+ $j = LWP::Simple::get($url);
+ if ($j) {
+ $j = JSON->new->utf8->allow_nonref->decode($j);
+ if ($j->{postcode}) {
+ $str .= "Nearest postcode to the pin placed on the map (automatically generated): $j->{postcode}[0] ($j->{postcode}[1]m away)\n\n";
+ }
+ }
+ return $str;
+}
+