summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-01-19 20:14:41 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-01-19 20:14:41 +0100
commit1ca70b38ed92aaf1a52418ee91bd2d194a556baf (patch)
tree478278ee0a2d4aac048fad67f60eddf697c51c40
parenta7f027fe14d59ca57f49286586d546ea4c132836 (diff)
Add support for up to two stopovers
-rwxr-xr-xbin/dbris38
-rw-r--r--lib/Travel/Routing/DE/DBRIS.pm15
2 files changed, 45 insertions, 8 deletions
diff --git a/bin/dbris b/bin/dbris
index 769777b..d131378 100755
--- a/bin/dbris
+++ b/bin/dbris
@@ -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
diff --git a/lib/Travel/Routing/DE/DBRIS.pm b/lib/Travel/Routing/DE/DBRIS.pm
index 63f6d35..6f57dcf 100644
--- a/lib/Travel/Routing/DE/DBRIS.pm
+++ b/lib/Travel/Routing/DE/DBRIS.pm
@@ -86,6 +86,14 @@ sub new {
deutschlandTicketVorhanden => \0
};
+ for my $via ( @{ $conf{via} } ) {
+ my $via_stop = { id => $via->{stop}->id };
+ if ( $via->{duration} ) {
+ $via_stop->{aufenthaltsdauer} = 0 + $via->{duration};
+ }
+ push( @{ $req->{zwischenhalte} }, $via_stop );
+ }
+
if ( @{ $conf{discounts} // [] } ) {
$req->{reisende}[0]{ermaessigungen} = [];
}
@@ -346,6 +354,13 @@ the requested itinerary.
A Travel::Status::DE::DBRIS::Location(3pm) instance describing the destination
of the requested itinerary.
+=item B<via> => I<arrayref>
+
+An arrayref containing up to two hashrefs that describe stopovers which must
+be part of the requested itinerary. Each hashref consists of two keys:
+B<stop> (Travel::Status::DE::DBRIS::Location(3pm) object, mandatory) and
+B<duration> (stopover duration in minutes, optional, default: 0).
+
=item B<cache> => I<cache>
A Cache::File(3pm) instance used for caching bahn.de requests.