diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-11-28 21:34:52 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-11-28 21:35:38 +0100 |
commit | 45ac5062d9647698ca50310d2b43e81126d0fc95 (patch) | |
tree | 4e99a22578f5fb5afae7144d2237e966dc49c8ce /bin | |
parent | a007ccc75d1df1a285284fdbc096d41c0e4881fe (diff) |
hafas-m --via: show estimated arrival time
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/hafas-m | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/bin/hafas-m b/bin/hafas-m index f515abf..602f639 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -11,7 +11,7 @@ use Encode qw(decode); use JSON; use Getopt::Long qw(:config no_ignore_case); use List::MoreUtils qw(uniq); -use List::Util qw(any first max); +use List::Util qw(first max); use Travel::Status::DE::HAFAS; my ( $date, $time, $language ); @@ -203,17 +203,17 @@ sub show_similar_stops { sub journey_has_via { my ( $journey, $via ) = @_; - if ($via =~ m{ ^ [0-9,]+ $ }x) { - for my $eva (split(qr{,}, $via)) { - if ( any { $_->loc->eva == $eva } $journey->route ) { - return 1; + if ( $via =~ m{ ^ [0-9,]+ $ }x ) { + for my $eva ( split( qr{,}, $via ) ) { + if ( my $stop = first { $_->loc->eva == $eva } $journey->route ) { + return $stop; } } return; } - if ( any { $_->loc->name =~ m{$via}io } $journey->route ) { - return 1; + if ( my $stop = first { $_->loc->name =~ m{$via}io } $journey->route ) { + return $stop; } return; } @@ -493,20 +493,31 @@ for my $d (@results) { . $info_line; } - push( - @output, - [ - $d->is_cancelled ? '--:--' : $d->datetime->strftime('%H:%M'), - $d->is_cancelled - ? q{} - : format_delay( $d->delay, $delay_len ), - $d->name, - $d->route_end, - ( $d->platform // q{} ) . ( $d->is_changed_platform ? ' !' : q{} ), - $info_line, - $d - ] - ); + my $entry = [ + $d->is_cancelled ? '--:--' : $d->datetime->strftime('%H:%M'), + $d->is_cancelled + ? q{} + : format_delay( $d->delay, $delay_len ), + $d->name, + $d->route_end, + ( $d->platform // q{} ) . ( $d->is_changed_platform ? ' !' : q{} ), + $info_line, + $d + ]; + + if ($via) { + my $stop = journey_has_via( $d, $via ); + + # HAFAS does not provide real-time data for route entries, so we have to guesstimate the arrival time + $entry->[0] .= ' → ' + . ( + $stop->arr_cancelled + ? '--:--' + : $stop->arr->add( minutes => $d->delay // 0 )->strftime('%H:%M') + ); + } + + push( @output, $entry, ); } display_result(@output); |