aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311/GetServiceRequests.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-10-16 12:37:52 +0100
committerMatthew Somerville <matthew@mysociety.org>2020-04-02 17:14:20 +0100
commit1f0473c9844b6e32338d1c1af6e368f3387e8890 (patch)
treede1edb52f27957ad4c6c35be850f91389ca09f16 /perllib/Open311/GetServiceRequests.pm
parentd44c06c213bc73632893ab58421ab98b7058b913 (diff)
Combine and improve fetch-comments/reports scripts
Make them take start/end hour arguments, cope if only one given, optional body, and combine them together in one `fetch` script.
Diffstat (limited to 'perllib/Open311/GetServiceRequests.pm')
-rw-r--r--perllib/Open311/GetServiceRequests.pm22
1 files changed, 13 insertions, 9 deletions
diff --git a/perllib/Open311/GetServiceRequests.pm b/perllib/Open311/GetServiceRequests.pm
index a9ec88a70..e5fd6438e 100644
--- a/perllib/Open311/GetServiceRequests.pm
+++ b/perllib/Open311/GetServiceRequests.pm
@@ -10,6 +10,7 @@ use DateTime::Format::W3CDTF;
has system_user => ( is => 'rw' );
has start_date => ( is => 'ro', default => sub { undef } );
has end_date => ( is => 'ro', default => sub { undef } );
+has body => ( is => 'ro', default => sub { undef } );
has fetch_all => ( is => 'rw', default => 0 );
has verbose => ( is => 'ro', default => 0 );
has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } );
@@ -27,6 +28,10 @@ sub fetch {
}
);
+ if ( $self->body ) {
+ $bodies = $bodies->search( { name => $self->body } );
+ }
+
while ( my $body = $bodies->next ) {
my $o = $self->create_open311_object( $body );
@@ -55,18 +60,17 @@ sub create_problems {
my $args = {};
- if ( $self->start_date || $self->end_date ) {
- return 0 unless $self->start_date && $self->end_date;
-
+ my $dt = DateTime->now();
+ if ($self->start_date) {
$args->{start_date} = DateTime::Format::W3CDTF->format_datetime( $self->start_date );
- $args->{end_date} = DateTime::Format::W3CDTF->format_datetime( $self->end_date );
} elsif ( !$self->fetch_all ) {
- my $end_dt = DateTime->now();
- my $start_dt = $end_dt->clone;
- $start_dt->add( hours => -1 );
+ $args->{start_date} = DateTime::Format::W3CDTF->format_datetime( $dt->clone->add(hours => -1) );
+ }
- $args->{start_date} = DateTime::Format::W3CDTF->format_datetime( $start_dt );
- $args->{end_date} = DateTime::Format::W3CDTF->format_datetime( $end_dt );
+ if ($self->end_date) {
+ $args->{end_date} = DateTime::Format::W3CDTF->format_datetime( $self->end_date );
+ } elsif ( !$self->fetch_all ) {
+ $args->{end_date} = DateTime::Format::W3CDTF->format_datetime( $dt );
}
my $requests = $open311->get_service_requests( $args );