summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-10-03 11:36:05 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-10-03 11:36:05 +0200
commit6fa6997cb1bb859272ad3f426ab0e0bb94065c7e (patch)
treebd4be6b92610ac76fbac493ef1cfe6e74a34c748 /bin
parent296da9b358d5c7258fc056db6ce3b3cf044fa99e (diff)
efa-m: add --json option
Diffstat (limited to 'bin')
-rwxr-xr-xbin/efa-m17
1 files changed, 14 insertions, 3 deletions
diff --git a/bin/efa-m b/bin/efa-m
index 657d3f7..444d31f 100755
--- a/bin/efa-m
+++ b/bin/efa-m
@@ -10,7 +10,8 @@ binmode( STDOUT, ':encoding(utf-8)' );
use Encode qw(decode);
use Getopt::Long qw(:config no_ignore_case bundling);
-use List::Util qw(first max none);
+use JSON;
+use List::Util qw(first max none);
use Travel::Status::DE::EFA;
my $service = 'VRR';
@@ -18,6 +19,7 @@ my $efa_url;
my $efa_encoding;
my $use_cache = 1;
my $cache;
+my $json_output;
my ( $date, $time, $input_type, $list_lines, $offset, $relative_times );
my ( $full_routes, $filter_via, $show_jid );
my ( $timeout, $developer_mode );
@@ -57,8 +59,9 @@ GetOptions(
'v|via=s' => \$filter_via,
'V|track-via=s' => \$filter_via,
'cache!' => \$use_cache,
- 'version' => \&show_version,
+ 'json' => \$json_output,
'devmode' => \$developer_mode,
+ 'version' => \&show_version,
) or show_help(1);
@@ -497,7 +500,15 @@ if ( my $err = $efa->errstr ) {
exit 2;
}
-if ($stopseq) {
+if ($json_output) {
+ if ($stopseq) {
+ say JSON->new->convert_blessed->encode( $efa->result );
+ }
+ else {
+ say JSON->new->convert_blessed->encode( [ $efa->results ] );
+ }
+}
+elsif ($stopseq) {
show_stopseq();
}
elsif ($list_lines) {