diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-01-19 20:14:41 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-01-19 20:14:41 +0100 |
commit | 1ca70b38ed92aaf1a52418ee91bd2d194a556baf (patch) | |
tree | 478278ee0a2d4aac048fad67f60eddf697c51c40 /bin | |
parent | a7f027fe14d59ca57f49286586d546ea4c132836 (diff) |
Add support for up to two stopovers
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/dbris | 38 |
1 files changed, 30 insertions, 8 deletions
@@ -65,14 +65,26 @@ if ($use_cache) { } } -my ( $from_raw, $to_raw ) = @ARGV; - -if ( not( $from_raw and $to_raw ) ) { +my ( $from_raw, @via_raw, $to_raw ); +if ( @ARGV < 2 ) { show_help(1); } +elsif ( @ARGV == 2 ) { + ( $from_raw, $to_raw ) = @ARGV; +} +elsif ( @ARGV <= 4 ) { + ( $from_raw, @via_raw ) = @ARGV; + $to_raw = pop(@via_raw); +} sub get_stop { - my ($stop) = @_; + my ( $stop, $is_via ) = @_; + my $stopover_duration; + + if ( $is_via and $stop =~ s{ : (?<duration> \d+ ) $ }{}x ) { + $stopover_duration = $+{duration}; + } + my $ris = Travel::Status::DE::DBRIS->new( cache => $cache, locationSearch => $stop, @@ -85,6 +97,12 @@ sub get_stop { my $found; for my $result ( $ris->results ) { if ( defined $result->eva ) { + if ($is_via) { + return { + stop => $result, + duration => $stopover_duration, + }; + } return $result; } } @@ -93,8 +111,9 @@ sub get_stop { } my %opt = ( - from => get_stop($from_raw), - to => get_stop($to_raw), + from => get_stop( $from_raw, 0 ), + to => get_stop( $to_raw, 0 ), + via => [ map { get_stop( $_, 1 ) } @via_raw ], language => $language, cache => $cache, developer_mode => $developer_mode, @@ -340,7 +359,8 @@ dbris - Interface to bahn.de public transit routing service =head1 SYNOPSIS -B<dbris> [B<-d> I<DD.MM.YYYY>] [B<-t> I<HH:MM>] [...] I<from-stop> I<to-stop> +B<dbris> [B<-d> I<DD.MM.YYYY>] [B<-t> I<HH:MM>] [...] I<from-stop> +[I<via-stop>[:I<duration>] [I<via-stop>[:I<duration>]]] I<to-stop> =head1 VERSION @@ -349,7 +369,9 @@ version 0.01 =head1 DESCRIPTION B<dbris> is an interface to the public transport routing service available on -bahn.de. It requests connections between two stops and prints the results. +bahn.de. It requests connections between I<from-stop> and I<to-stop> and prints +the result. If one or two I<via-stop>s are specified, it only returns matching +connections, with an optional minimum stopover I<duration> given in minutes. =head1 OPTIONS |