diff options
Diffstat (limited to 'perllib/Open311')
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 19 | ||||
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 33 |
2 files changed, 44 insertions, 8 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 99e1d5758..e337c0f57 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -10,6 +10,7 @@ has system_user => ( is => 'rw' ); has start_date => ( is => 'ro', default => undef ); has end_date => ( is => 'ro', default => undef ); has suppress_alerts => ( is => 'rw', default => 0 ); +has verbose => ( is => 'ro', default => 0 ); sub fetch { my $self = shift; @@ -31,6 +32,13 @@ sub fetch { jurisdiction => $council->jurisdiction, ); + if ( $council->area_id =~ /2482/ ) { + my $endpoints = $o->endpoints; + $endpoints->{update} = 'update.xml'; + $endpoints->{service_request_updates} = 'update.xml'; + $o->endpoints( $endpoints ); + } + $self->suppress_alerts( $council->suppress_alerts ); $self->system_user( $council->comment_user ); $self->update_comments( $o, { areaid => $council->area_id }, ); @@ -47,12 +55,21 @@ sub update_comments { push @args, $self->start_date; push @args, $self->end_date; + # default to asking for last 2 hours worth if not Bromley + } elsif ( $council_details->{areaid} != 2482 ) { + my $end_dt = DateTime->now(); + my $start_dt = $end_dt->clone; + $start_dt->add( hours => -2 ); + + push @args, DateTime::Format::W3CDTF->format_datetime( $start_dt ); + push @args, DateTime::Format::W3CDTF->format_datetime( $end_dt ); } my $requests = $open311->get_service_request_updates( @args ); unless ( $open311->success ) { - warn "Failed to fetch ServiceRequest Updates: " . $open311->error; + warn "Failed to fetch ServiceRequest Updates for " . $council_details->{areaid} . ":\n" . $open311->error + if $self->verbose; return 0; } diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index 7b5f4c7fe..e8ae56833 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -21,6 +21,7 @@ sub process_councils { while ( my $council = $self->council_list->next ) { next unless $council->endpoint; + next unless lc($council->send_method) eq 'open311'; $self->_current_council( $council ); $self->process_council; } @@ -40,7 +41,9 @@ sub process_council { my $list = $open311->get_service_list; unless ( $list ) { - warn "ERROR: no service list found for " . $self->_current_council->area_id . "\n"; + my $id = $self->_current_council->area_id; + warn "Council $id - http://mapit.mysociety.org/area/$id.html - did not return a service list\n" + if $self->verbose >= 1; return; } $self->process_services( $list ); @@ -82,7 +85,7 @@ sub process_service { $self->_current_service->{description} : $self->_current_service->{service_name}; - print $self->_current_service->{service_code} . ': ' . $category . "\n" if $self->verbose; + print $self->_current_service->{service_code} . ': ' . $category . "\n" if $self->verbose >= 2; my $contacts = FixMyStreet::App->model( 'DB::Contact')->search( { area_id => $self->_current_council->area_id, @@ -122,7 +125,7 @@ sub _handle_existing_contact { my $service_name = $self->_normalize_service_name; - print $self->_current_council->area_id . " already has a contact for service code " . $self->_current_service->{service_code} . "\n" if $self->verbose; + print $self->_current_council->area_id . " already has a contact for service code " . $self->_current_service->{service_code} . "\n" if $self->verbose >= 2; if ( $contact->deleted || $service_name ne $contact->category || $self->_current_service->{service_code} ne $contact->email ) { eval { @@ -140,11 +143,18 @@ sub _handle_existing_contact { }; if ( $@ ) { - warn "Failed to update contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}: $@\n"; + warn "Failed to update contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}: $@\n" + if $self->verbose >= 1; return; } } + if ( $contact and lc( $self->_current_service->{metadata} ) eq 'true' ) { + $self->_add_meta_to_contact( $contact ); + } elsif ( $contact and $contact->extra and lc( $self->_current_service->{metadata} ) eq 'false' ) { + $contact->update( { extra => undef } ); + } + push @{ $self->found_contacts }, $self->_current_service->{service_code}; } @@ -170,7 +180,8 @@ sub _create_contact { }; if ( $@ ) { - warn "Failed to create contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}: $@\n"; + warn "Failed to create contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}: $@\n" + if $self->verbose >= 1; return; } @@ -180,14 +191,14 @@ sub _create_contact { if ( $contact ) { push @{ $self->found_contacts }, $self->_current_service->{service_code}; - print "created contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}\n" if $self->verbose; + print "created contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}\n" if $self->verbose >= 2; } } sub _add_meta_to_contact { my ( $self, $contact ) = @_; - print "Fetching meta data for $self->_current_service->{service_code}\n" if $self->verbose; + print "Fetching meta data for $self->_current_service->{service_code}\n" if $self->verbose >= 2; my $meta_data = $self->_current_open311->get_service_meta_info( $self->_current_service->{service_code} ); if ( ref $meta_data->{ attributes }->{ attribute } eq 'HASH' ) { @@ -196,6 +207,14 @@ sub _add_meta_to_contact { ]; } + if ( ! $meta_data->{attributes}->{attribute} ) { + warn sprintf( "Empty meta data for %s at %s", + $self->_current_service->{service_code}, + $self->_current_council->endpoint ) + if $self->verbose; + return; + } + # turn the data into something a bit more friendly to use my @meta = # remove trailing colon as we add this when we display so we don't want 2 |