From a007ccc75d1df1a285284fdbc096d41c0e4881fe Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Mon, 27 Nov 2023 07:00:52 +0100 Subject: hafas-m: add -v/--via --- bin/hafas-m | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/hafas-m b/bin/hafas-m index 222a35d..f515abf 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -11,13 +11,14 @@ 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); +use List::Util qw(any first max); use Travel::Status::DE::HAFAS; my ( $date, $time, $language ); -my $arrivals = 0; -my $types = q{}; +my $arrivals; +my $types = q{}; my $developer_mode; +my $via; my ( $json_output, $raw_json_output ); my ( $list_services, $service ); my ( @excluded_mots, @exclusive_mots ); @@ -37,6 +38,7 @@ GetOptions( 'm|mot=s' => \$types, 's|service=s' => \$service, 't|time=s' => \$time, + 'v|via=s' => \$via, 'V|version' => \&show_version, 'devmode' => \$developer_mode, 'json' => \$json_output, @@ -198,6 +200,24 @@ sub show_similar_stops { return; } +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; + } + } + return; + } + + if ( any { $_->loc->name =~ m{$via}io } $journey->route ) { + return 1; + } + return; +} + sub display_result { my (@lines) = @_; @@ -434,6 +454,10 @@ my @results = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $_->datetime->epoch, $_ ] } $status->results; +if ($via) { + @results = grep { journey_has_via( $_, $via ) } @results; +} + my $delay_len = 0; my $occupancy_len = 0; for my $d (@results) { @@ -623,6 +647,13 @@ to DB (Deutsche Bahn). See B<--list> for a list of known services. Time to list departures for. Default: now. +=item B<-v>, B<--via> I|I,I,... + +Only show departures that pass by I (or arivals that have passed by +I). If I is given as a list of numeric EVA IDs, only +arrivals/departures with an exact EVA ID match are shown. Otherwise I +is treated as a regular expression and matched against stop names. + =item B<-V>, B<--version> Show version information and exit. -- cgit v1.2.3