diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-10-16 12:37:52 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-04-02 17:14:20 +0100 |
commit | 1f0473c9844b6e32338d1c1af6e368f3387e8890 (patch) | |
tree | de1edb52f27957ad4c6c35be850f91389ca09f16 /bin | |
parent | d44c06c213bc73632893ab58421ab98b7058b913 (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 'bin')
-rwxr-xr-x | bin/fetch | 58 | ||||
-rwxr-xr-x | bin/fetch-comments | 27 | ||||
-rwxr-xr-x | bin/fetch-comments-24hs | 39 | ||||
-rwxr-xr-x | bin/fetch-reports | 27 | ||||
-rwxr-xr-x | bin/fetch-reports-24hs | 37 | ||||
-rwxr-xr-x | bin/open311-update-reports | 2 |
6 files changed, 75 insertions, 115 deletions
diff --git a/bin/fetch b/bin/fetch new file mode 100755 index 000000000..5608cf195 --- /dev/null +++ b/bin/fetch @@ -0,0 +1,58 @@ +#!/usr/bin/env perl +# +# This script utilises Open311 as described at +# http://wiki.open311.org/GeoReport_v2/#get-service-requests +# and/or the Open311 extension explained at +# https://github.com/mysociety/FixMyStreet/wiki/Open311-FMS---Proposed-differences-to-Open311 +# to fetch service requests or updates on service requests. + +use strict; +use warnings; +use v5.14; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + +use DateTime; +use Getopt::Long::Descriptive; +use Open311::GetServiceRequests; +use Open311::GetServiceRequestUpdates; + +my ($opts, $usage) = describe_options( + '%c %o', + ['reports', 'fetch reports'], + ['updates', 'fetch updates'], + ['start|s:i', 'start time to use (hours before now), defaults to one (reports) or two (updates)' ], + ['end|e:i', 'end time to use (hours before now), defaults to zero' ], + ['body|b:s', 'body name to only fetch this body' ], + ['verbose|v', 'more verbose output'], + ['help|h', "print usage message and exit" ], +); +$usage->die if $opts->help; + +my %params = ( + verbose => $opts->verbose, + body => $opts->body, +); + +my $dt = DateTime->now(); +if ($opts->start) { + $params{start_date} = $dt->clone->add(hours => -$opts->start); +} +if ($opts->end) { + $params{end_date} = $dt->clone->add(hours => -$opts->end); +} + +if ($opts->reports) { + my $reports = Open311::GetServiceRequests->new(%params); + $reports->fetch; +} + +if ($opts->updates) { + my $updates = Open311::GetServiceRequestUpdates->new(%params); + $updates->fetch; +} diff --git a/bin/fetch-comments b/bin/fetch-comments index 55ba70d85..0fb30f236 100755 --- a/bin/fetch-comments +++ b/bin/fetch-comments @@ -1,25 +1,6 @@ -#!/usr/bin/env perl +#!/bin/bash # -# This script utilises the Open311 extension explained at -# https://github.com/mysociety/FixMyStreet/wiki/Open311-FMS---Proposed-differences-to-Open311 -# to fetch updates on service requests. +# Wrapper to call new script -use strict; -use warnings; -require 5.8.0; - -BEGIN { - use File::Basename qw(dirname); - use File::Spec; - my $d = dirname(File::Spec->rel2abs($0)); - require "$d/../setenv.pl"; -} - -use CronFns; -my ($verbose, $nomail) = CronFns::options(); - -use Open311::GetServiceRequestUpdates; - -my $updates = Open311::GetServiceRequestUpdates->new( verbose => $verbose ); - -$updates->fetch; +DIR="$(cd "$(dirname "$BASH_SOURCE")" && pwd -P)" +$DIR/fetch --updates diff --git a/bin/fetch-comments-24hs b/bin/fetch-comments-24hs index df208439e..86675be4c 100755 --- a/bin/fetch-comments-24hs +++ b/bin/fetch-comments-24hs @@ -1,37 +1,6 @@ -#!/usr/bin/env perl +#!/bin/bash # -# This script utilises the Open311 extension explained at -# https://github.com/mysociety/FixMyStreet/wiki/Open311-FMS---Proposed-differences-to-Open311 -# to fetch updates on service requests from the past 24 hours, to check none -# were missed. +# Wrapper to call new script -use strict; -use warnings; -require 5.8.0; - -BEGIN { - use File::Basename qw(dirname); - use File::Spec; - my $d = dirname(File::Spec->rel2abs($0)); - require "$d/../setenv.pl"; -} - -use DateTime; -use DateTime::Format::W3CDTF; - -use CronFns; -my ($verbose, $nomail) = CronFns::options(); - -use Open311::GetServiceRequestUpdates; - -my $dt = DateTime->now(); -my $dt_24hrs_ago = $dt->clone; -$dt_24hrs_ago->add( hours => -24 ); - -my $updates = Open311::GetServiceRequestUpdates->new( - verbose => 1, - start_date => DateTime::Format::W3CDTF->format_datetime( $dt_24hrs_ago ), - end_date => DateTime::Format::W3CDTF->format_datetime( $dt ) -); - -$updates->fetch; +DIR="$(cd "$(dirname "$BASH_SOURCE")" && pwd -P)" +$DIR/fetch --updates --start 24 diff --git a/bin/fetch-reports b/bin/fetch-reports index 20de10f4b..11bb0c44a 100755 --- a/bin/fetch-reports +++ b/bin/fetch-reports @@ -1,25 +1,6 @@ -#!/usr/bin/env perl +#!/bin/bash # -# This script utilises Open311 as described at -# http://wiki.open311.org/GeoReport_v2/#get-service-requests -# to fetch service requests. +# Wrapper to call new script -use strict; -use warnings; -require 5.8.0; - -BEGIN { - use File::Basename qw(dirname); - use File::Spec; - my $d = dirname(File::Spec->rel2abs($0)); - require "$d/../setenv.pl"; -} - -use CronFns; -my ($verbose, $nomail) = CronFns::options(); - -use Open311::GetServiceRequests; - -my $reports = Open311::GetServiceRequests->new( verbose => $verbose ); - -$reports->fetch; +DIR="$(cd "$(dirname "$BASH_SOURCE")" && pwd -P)" +$DIR/fetch --reports diff --git a/bin/fetch-reports-24hs b/bin/fetch-reports-24hs index ec0eabc2e..ffc1e9e72 100755 --- a/bin/fetch-reports-24hs +++ b/bin/fetch-reports-24hs @@ -1,35 +1,6 @@ -#!/usr/bin/env perl +#!/bin/bash # -# This script utilises Open311 as described at -# http://wiki.open311.org/GeoReport_v2/#get-service-requests -# to fetch service requests. +# Wrapper to call new script -use strict; -use warnings; -require 5.8.0; - -BEGIN { - use File::Basename qw(dirname); - use File::Spec; - my $d = dirname(File::Spec->rel2abs($0)); - require "$d/../setenv.pl"; -} - -use DateTime; - -use CronFns; -my ($verbose, $nomail) = CronFns::options(); - -use Open311::GetServiceRequests; - -my $dt = DateTime->now(); -my $dt_24hrs_ago = $dt->clone; -$dt_24hrs_ago->add( hours => -24 ); - -my $reports = Open311::GetServiceRequests->new( - verbose => 1, - start_date => $dt_24hrs_ago, - end_date => $dt -); - -$reports->fetch; +DIR="$(cd "$(dirname "$BASH_SOURCE")" && pwd -P)" +$DIR/fetch --reports --start 24 diff --git a/bin/open311-update-reports b/bin/open311-update-reports index 378f8e8bc..2d384b813 100755 --- a/bin/open311-update-reports +++ b/bin/open311-update-reports @@ -4,7 +4,7 @@ # (by fetching all reports for a body and looking for updates). If possible, # please use the extension explained at # https://github.com/mysociety/FixMyStreet/wiki/Open311-FMS---Proposed-differences-to-Open311 -# and the fetch-comments/send-comments scripts. +# and the fetch/send-comments scripts. use strict; use warnings; |