summaryrefslogtreecommitdiff
path: root/bin/hafas
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-11-12 09:33:28 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2023-11-12 09:33:28 +0100
commita6068c9a4af9a6ddaa9f16204a1d85828663c90b (patch)
tree85c43b5a4d839b8ded8ebdf5af9c662690a97451 /bin/hafas
parentb3915fbeeb0d3b732d76bef878c66b8ff5b0c814 (diff)
hafas: do not show duration if the journey is impossible
Diffstat (limited to 'bin/hafas')
-rwxr-xr-xbin/hafas27
1 files changed, 18 insertions, 9 deletions
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);
}