diff options
Diffstat (limited to 'bin')
-rw-r--r-- | bin/generate_council_location | 26 | ||||
-rwxr-xr-x | bin/open311-populate-service-list | 12 | ||||
-rw-r--r-- | bin/open311-update-reports | 21 | ||||
-rwxr-xr-x | bin/send-reports | 53 |
4 files changed, 108 insertions, 4 deletions
diff --git a/bin/generate_council_location b/bin/generate_council_location new file mode 100644 index 000000000..36bf14d04 --- /dev/null +++ b/bin/generate_council_location @@ -0,0 +1,26 @@ +use strict; +use JSON; +use LWP::Simple; + +my $id = shift; + +my $url = sprintf( 'http://mapit.mysociety.org/area/%s/geometry', $id); + +my $json = get( $url ); +my $geo = decode_json( $json ); + +my $max_lat = $geo->{max_lat}; +my $min_lat = $geo->{min_lat}; +my $max_lon = $geo->{max_lon}; +my $min_lon = $geo->{min_lon}; +my $c_lat = $geo->{centre_lat}; +my $c_lon = $geo->{centre_lon}; + +my $spn_lat = $max_lat - $min_lat; +my $spn_lon = $max_lon - $min_lon; + +print <<"EOT"; + centre => '$c_lat,$c_lon', + span => '$spn_lat,$spn_lon', + bounds => [ '$min_lat,$min_lon','$max_lat,$max_lon' ], +EOT diff --git a/bin/open311-populate-service-list b/bin/open311-populate-service-list new file mode 100755 index 000000000..36e04f5a6 --- /dev/null +++ b/bin/open311-populate-service-list @@ -0,0 +1,12 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use FixMyStreet::App; +use Open311::PopulateServiceList; + + +my $council_list = FixMyStreet::App->model('DB::Open311conf'); +my $p = Open311::PopulateServiceList->new( council_list => $council_list ); + +$p->process_councils; diff --git a/bin/open311-update-reports b/bin/open311-update-reports new file mode 100644 index 000000000..41c9c4546 --- /dev/null +++ b/bin/open311-update-reports @@ -0,0 +1,21 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Open311::GetUpdates; +use FixMyStreet::App; + +# FIXME - make this configurable and/or better +my $system_user = FixMyStreet::App->model('DB::User')->find_or_create( + { + email => FixMyStreet::App->config->{'CONTACT_EMAIL'}, + name => 'System User', + } +); + +my $council_list = FixMyStreet::App->model('DB::Open311conf'); + +my $update = Open311::GetUpdates->new( + council_list => $council_list, + system_user => $system_user +)->get_updates; diff --git a/bin/send-reports b/bin/send-reports index fc8ee6e45..427d02ec8 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -27,6 +27,8 @@ use mySociety::EmailUtil; use mySociety::MaPit; use mySociety::Web qw(ent); +use Open311; + # Set up site, language etc. my ($verbose, $nomail) = CronFns::options(); my $base_url = mySociety::Config::get('BASE_URL'); @@ -39,7 +41,7 @@ my $unsent = FixMyStreet::App->model("DB::Problem")->search( { } ); my (%notgot, %note); while (my $row = $unsent->next) { - + my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new(); # Cobranded and non-cobranded messages can share a database. In this case, the conf file @@ -75,7 +77,7 @@ while (my $row = $unsent->next) { $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} = ''; - + # If we are in the UK include eastings and northings, and nearest stuff $h{easting_northing} = ''; if ( $cobrand->country eq 'GB' ) { @@ -93,7 +95,7 @@ while (my $row = $unsent->next) { $h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude}, $row ); } - my (@to, @recips, $template, $areas_info); + my (@to, @recips, $template, $areas_info, @open311_councils); if ($site eq 'emptyhomes') { my $council = $row->council; @@ -135,6 +137,9 @@ while (my $row = $unsent->next) { $h{category} = 'Customer Services' if $h{category} eq 'Other'; } elsif ($areas_info->{$council}->{type} eq 'LBO') { # London $send_web = 'london'; + } elsif ( my $endpoint = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $council, endpoint => { '!=', '' } } )->first ) { + push @open311_councils, $endpoint; + $send_web = 'open311'; } else { my $contact = FixMyStreet::App->model("DB::Contact")->find( { deleted => 0, @@ -247,6 +252,46 @@ while (my $row = $unsent->next) { if (!$nomail) { $result *= post_london_report( $row, %h ); } + } elsif ($send_web eq 'open311') { + foreach my $conf ( @open311_councils ) { + print 'posting to end point for ' . $conf->area_id . "\n" if $verbose; + + my $contact = FixMyStreet::App->model("DB::Contact")->find( { + deleted => 0, + area_id => $conf->area_id, + category => $row->category + } ); + + my $open311 = Open311->new( + jurisdiction => $conf->jurisdiction, + endpoint => $conf->endpoint, + api_key => $conf->api_key, + ); + + # non standard west berks end points + if ( $row->council =~ /2619/ ) { + $open311->endpoints( { services => 'Services', requests => 'Requests' } ); + } + + # required to get round issues with CRM constraints + if ( $row->council =~ /2218/ ) { + $row->user->name( $row->user->id . ' ' . $row->user->name ); + } + + my $resp = $open311->send_service_request( $row, \%h, $contact->email ); + + # make sure we don't save user changes from above + if ( $row->council =~ /2218/ ) { + $row->discard_changes(); + } + + if ( $resp ) { + $row->external_id( $resp ); + $result *= 0; + } else { + $result *= 1; + } + } } if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { @@ -425,7 +470,7 @@ sub post_london_report { # Nearest things sub london_lookup { - my $org = shift; + my $org = shift || ''; my $str = "Unknown ($org)"; open(FP, "$FindBin::Bin/../data/dft.csv"); while (<FP>) { |