summaryrefslogtreecommitdiff
path: root/bin/hafas-m
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2023-05-02 18:16:55 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2023-05-02 18:16:55 +0200
commit7349b3ee9f135888a3814e14d68358f01fea6079 (patch)
treee76e5a749f5ccf84df01c055ee59bf6839bc24a5 /bin/hafas-m
parent1ae5aa27f60db4d6f3d522bc2812e859f630413c (diff)
hafas-m: add --json option
Diffstat (limited to 'bin/hafas-m')
-rwxr-xr-xbin/hafas-m19
1 files changed, 18 insertions, 1 deletions
diff --git a/bin/hafas-m b/bin/hafas-m
index 623cd36..3533cf4 100755
--- a/bin/hafas-m
+++ b/bin/hafas-m
@@ -7,7 +7,8 @@ our $VERSION = '4.10';
use utf8;
use DateTime;
-use Encode qw(decode);
+use Encode qw(decode);
+use JSON;
use Getopt::Long qw(:config no_ignore_case);
use List::MoreUtils qw(uniq);
use List::Util qw(first max);
@@ -17,6 +18,7 @@ my ( $date, $time );
my $arrivals = 0;
my $types = q{};
my $developer_mode;
+my $json_output;
my ( $list_services, $service );
my ( @excluded_mots, @exclusive_mots );
@@ -36,6 +38,7 @@ GetOptions(
't|time=s' => \$time,
'V|version' => \&show_version,
'devmode' => \$developer_mode,
+ 'json' => \$json_output,
'list' => \$list_services,
) or show_help(1);
@@ -245,6 +248,16 @@ if ( my $err = $status->errstr ) {
exit 2;
}
+if ($json_output) {
+ if ( $opt{journey} ) {
+ say JSON->new->convert_blessed->encode( [ $status->result ] );
+ }
+ else {
+ say JSON->new->convert_blessed->encode( [ $status->results ] );
+ }
+ exit 0;
+}
+
if ( $opt{geoSearch} ) {
for my $result ( $status->results ) {
printf(
@@ -384,6 +397,10 @@ the end station.
Date to list departures for. Default: today.
+=item B<--json>
+
+Print result(s) as JSON.
+
=item B<--list>
List known HAFAS installations. A HAFAS service from this list can be querie