From f9678526018e4b31e25a3d8435a5ffd60e0ebe4d Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 19 Nov 2023 11:33:35 +0100 Subject: hafas-m: Add --raw-json option --- bin/hafas-m | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/bin/hafas-m b/bin/hafas-m index faa2a90..ff13932 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -18,7 +18,7 @@ my ( $date, $time, $language ); my $arrivals = 0; my $types = q{}; my $developer_mode; -my $json_output; +my ( $json_output, $raw_json_output ); my ( $list_services, $service ); my ( @excluded_mots, @exclusive_mots ); @@ -40,6 +40,7 @@ GetOptions( 'V|version' => \&show_version, 'devmode' => \$developer_mode, 'json' => \$json_output, + 'raw-json' => \$raw_json_output, 'list' => \$list_services, ) or show_help(1); @@ -259,14 +260,20 @@ sub display_occupancy { if ( my $err = $status->errstr ) { say STDERR "Request error: ${err}"; - if ( $status->errcode - and ( $status->errcode eq 'H730' or $status->errcode eq 'LOCATION' ) ) + if ( $status->errcode + and ( $status->errcode eq 'H730' or $status->errcode eq 'LOCATION' ) + and not $raw_json_output ) { show_similar_stops(); } exit 2; } +if ($raw_json_output) { + say JSON->new->convert_blessed->encode( $status->{raw_json} ); + exit 0; +} + if ($json_output) { if ( $opt{journey} ) { say JSON->new->convert_blessed->encode( $status->result ); @@ -457,8 +464,8 @@ Date to list departures for. Default: today. =item B<--json> -Print result(s) as JSON. This is a dump of internal data structures and not -guaranteed to remain stable between minor versions. Please use the +Print result(s) as JSON and exit. This is a dump of internal data structures +and not guaranteed to remain stable between minor versions. Please use the Travel::Status::DE::HAFAS(3pm) module if you need a proper API. =item B<-l>, B<--language> I @@ -484,6 +491,11 @@ To show them exclusively, set I to I,I,... The I types depend on the used service. Use C<< -m help >> to list them. +=item B<--raw-json> + +Print unprocessed HAFAS response as JSON and exit. +Useful for debugging and development purposes. + =item B<-s>, B<--service> I Request arrivals/departures using the API provided by I, defaults -- cgit v1.2.3