diff options
author | Struan Donald <struan@exo.org.uk> | 2011-07-22 10:08:13 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-07-22 10:08:13 +0100 |
commit | 10b03426bb8a0d50f59f3de729746fab6650248a (patch) | |
tree | 444b7805e839dbc9a22b53ce34595bf5b1eb56f9 /bin/open311-populate-service-list | |
parent | 4a8e9e711dca602d657cbe24b4733c613b94c279 (diff) |
basic script to populate contacts from open311 service list
Diffstat (limited to 'bin/open311-populate-service-list')
-rw-r--r-- | bin/open311-populate-service-list | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/bin/open311-populate-service-list b/bin/open311-populate-service-list new file mode 100644 index 000000000..4fff0c501 --- /dev/null +++ b/bin/open311-populate-service-list @@ -0,0 +1,68 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use LWP::Simple; +use XML::Simple; +use FixMyStreet::App; + +use Data::Dumper; + +my $council = 1; +my $end_point = 'http://seeclicktest.com/open311/services.xml?lat=38.918978274355&lng=-77.0126581192017'; + +my $service_list = get( $end_point ); + +my $xml = XML::Simple->new(); +my $list = $xml->XMLin( $service_list ); +my @found_contacts; + +# print Dumper $list; + +foreach my $service ( @{ $list->{service} } ) { + print $service->{service_code} . ': ' . $service->{service_name} . "\n"; + my $contacts = FixMyStreet::App->model( 'DB::Contact')->search( + { + email => $service->{service_code}, + area_id => $council + } + ); + + my $contact = $contacts->first; + + if ( $contact ) { + print "$council already has a contact for service code " . $service->{service_code} . "\n"; + push @found_contacts, $service->{service_code}; + } else { + my $contact = FixMyStreet::App->model( 'DB::Contact')->create( + { + email => $service->{service_code}, + area_id => $council, + category => $service->{service_name}, + confirmed => 1, + deleted => 0, + editor => $0, + whenedited => \'ms_current_timestamp()', + note => 'created automatically by script', + } + ); + print "created contact for service code " . $service->{service_code} . " for council $council\n"; + } +} + +my $found_contacts = FixMyStreet::App->model( 'DB::Contact')->search( + { + email => { -not_in => \@found_contacts }, + area_id => $council, + deleted => 0, + } +); + +$found_contacts->update( + { + deleted => 1, + editor => $0, + whenedited => \'ms_current_timestamp()', + note => 'automatically marked as deleted by script' + } +); |