From a6068c9a4af9a6ddaa9f16204a1d85828663c90b Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 12 Nov 2023 09:33:28 +0100 Subject: hafas: do not show duration if the journey is impossible --- bin/hafas | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'bin') diff --git a/bin/hafas b/bin/hafas index d8fdc33..c2b8558 100755 --- a/bin/hafas +++ b/bin/hafas @@ -274,11 +274,14 @@ if ($json_output) { exit 0; } -for my $res ( @{ $hafas->{results} } ) { +for my $res ( $hafas->connections ) { - #if ($res->is_cancelled) { - # say "# cancelled\n"; - #} + my $cancelled; + for my $msg ( $res->messages ) { + if ( $msg->type eq 'C' and $msg->text =~ m{Fahrt fällt aus} ) { + $cancelled = 1; + } + } my $glance = q{}; for my $sec ( $res->sections ) { @@ -297,11 +300,17 @@ for my $res ( @{ $hafas->{results} } ) { } } - printf( - "%02d:%02d %s %s\n", - $res->duration->in_units( 'hours', 'minutes' ), - display_occupancies( $res->load ), $glance - ); + if ($cancelled) { + printf( "--:-- %s %s\n", display_occupancies( $res->load ), $glance ); + } + else { + printf( + "%02d:%02d %s %s\n", + $res->duration->in_units( 'hours', 'minutes' ), + display_occupancies( $res->load ), $glance + ); + } + for my $msg ( $res->messages ) { show_message($msg); } -- cgit v1.2.3