summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorBirte Kristina Friesel <birte.friesel@uos.de>2023-11-27 07:00:52 +0100
committerBirte Kristina Friesel <birte.friesel@uos.de>2023-11-27 07:00:52 +0100
commita007ccc75d1df1a285284fdbc096d41c0e4881fe (patch)
tree0a31639a89872f6a28bce479b5f3bfda6fb1f51c /bin
parent3ca0d070aedba762aa7a4d9fed442ecda51714a5 (diff)
hafas-m: add -v/--via
Diffstat (limited to 'bin')
-rwxr-xr-xbin/hafas-m37
1 files changed, 34 insertions, 3 deletions
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<stopname>|I<eva1>,I<eva2>,...
+
+Only show departures that pass by I<stopname> (or arivals that have passed by
+I<stopname>). If I<stopname> is given as a list of numeric EVA IDs, only
+arrivals/departures with an exact EVA ID match are shown. Otherwise I<stopname>
+is treated as a regular expression and matched against stop names.
+
=item B<-V>, B<--version>
Show version information and exit.