diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/update-all-reports | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/bin/update-all-reports b/bin/update-all-reports index 4c0e96d31..0f9231f87 100755 --- a/bin/update-all-reports +++ b/bin/update-all-reports @@ -16,19 +16,45 @@ BEGIN { require "$d/../setenv.pl"; } +use FixMyStreet::DB; use FixMyStreet::Script::UpdateAllReports; +use Path::Tiny; use Getopt::Long::Descriptive; +use JSON::MaybeXS; my ($opt, $usage) = describe_options( '%c %o', [ 'table', "Output JSON for old table-style page." ], - [ 'areas', "Include area IDs in output JSON." ], + [ 'body=i', "Restrict results to a particular body (dashboard-style)." ], + [ 'all-bodies', "Generate set of results for all bodies." ], + [ 'areas', "Include area IDs in output JSON (table-style)." ], [ 'help', "print usage message and exit", { shortcircuit => 1 } ], ); print($usage->text), exit if $opt->help; +my ($data, $filename); if ($opt->table) { - FixMyStreet::Script::UpdateAllReports::generate($opt->areas); + $data = FixMyStreet::Script::UpdateAllReports::generate($opt->areas); + output('all-reports', $data); +} elsif ($opt->all_bodies) { + my $bodies = FixMyStreet::DB->resultset("Body")->search({ deleted => 0 }); + while (my $body = $bodies->next) { + my $data = FixMyStreet::Script::UpdateAllReports::generate_dashboard($body->id); + output("all-reports-dashboard-" . $body->id, $data); + } +} elsif (my $body_id = $opt->body) { + my $body = FixMyStreet::DB->resultset("Body")->find({ id => $body_id }); + die "Could not find body $body_id" unless $body; + $data = FixMyStreet::Script::UpdateAllReports::generate_dashboard($body); + output("all-reports-dashboard-$body_id", $data); } else { - FixMyStreet::Script::UpdateAllReports::generate_dashboard(); + $data = FixMyStreet::Script::UpdateAllReports::generate_dashboard(); + output("all-reports-dashboard", $data); +} + +sub output { + my ($filename, $data) = @_; + my $json = encode_json($data); + path(FixMyStreet->path_to('../data/'))->mkpath; + path(FixMyStreet->path_to("../data/$filename.json"))->spew_utf8($json); } |