summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/dbris20
-rw-r--r--lib/Travel/Routing/DE/DBRIS.pm72
2 files changed, 66 insertions, 26 deletions
diff --git a/bin/dbris b/bin/dbris
index a1d23cc..e809ece 100755
--- a/bin/dbris
+++ b/bin/dbris
@@ -16,7 +16,7 @@ use Travel::Routing::DE::DBRIS;
my ( $date, $time, $from, $to, $language );
my $mots;
-my ( $first_class, $discounts );
+my ( $first_class, $passengers );
my $developer_mode;
my ( $json_output, $raw_json_output );
my $use_cache = 1;
@@ -36,12 +36,12 @@ my $output_reset = -t STDOUT ? "\033[0m" : q{};
GetOptions(
'd|date=s' => \$date,
- 'D|discounts=s' => \$discounts,
'h|help' => sub { show_help(0) },
'f|full-route' => \$show_full_route,
'first-class!' => \$first_class,
'm|modes-of-transit=s' => \$mots,
'l|language=s' => \$language,
+ 'p|passengers=s' => \$passengers,
't|time=s' => \$time,
'V|version' => \&show_version,
'cache!' => \$use_cache,
@@ -177,8 +177,18 @@ if ($mots) {
$opt{modes_of_transit} = [ grep { $known_mot{$_} } @mots ];
}
-if ($discounts) {
- $opt{discounts} = [ split( qr{, *}, $discounts ) ];
+if ($passengers) {
+ for my $passenger ( split( qr{; *}, $passengers ) ) {
+ my ( $type, $discounts ) = split( qr{ *: *}, $passenger );
+ $discounts = $discounts ? [ split( qr{, *}, $discounts ) ] : [];
+ push(
+ @{ $opt{passengers} },
+ {
+ type => $type,
+ discounts => $discounts,
+ }
+ );
+ }
}
sub show_help {
@@ -293,7 +303,7 @@ for my $connection ( $ris->connections ) {
$connection->duration->in_units( 'hours', 'minutes' ),
$connection->arr ? $connection->arr->strftime('%H:%M') : q{??:??},
format_occupancy($connection),
- defined $connection->price
+ ( defined $passengers and defined $connection->price )
? sprintf( ' %.2f %s', $connection->price, $connection->price_unit )
: q{},
$header,
diff --git a/lib/Travel/Routing/DE/DBRIS.pm b/lib/Travel/Routing/DE/DBRIS.pm
index 8bf6bbe..b19c7e9 100644
--- a/lib/Travel/Routing/DE/DBRIS.pm
+++ b/lib/Travel/Routing/DE/DBRIS.pm
@@ -21,6 +21,12 @@ our $VERSION = '0.01';
Travel::Routing::DE::DBRIS->mk_ro_accessors(qw(earlier later));
+my %passenger_type_map = (
+ adult => 'ERWACHSENER',
+ junior => 'JUGENDLICHER',
+ senior => 'SENIOR',
+);
+
# {{{ Constructors
sub new {
@@ -94,30 +100,50 @@ sub new {
push( @{ $req->{zwischenhalte} }, $via_stop );
}
- if ( @{ $conf{discounts} // [] } ) {
- $req->{reisende}[0]{ermaessigungen} = [];
+ if ( @{ $conf{passengers} // [] } ) {
+ $req->{reisende} = [];
}
- for my $discount ( @{ $conf{discounts} // [] } ) {
- my ( $type, $class );
- for my $num (qw(25 50 100)) {
- if ( $discount eq "bc${num}" ) {
- $type = "BAHNCARD${num}";
- $class = 'KLASSE_2';
+
+ for my $passenger ( @{ $conf{passengers} // [] } ) {
+ if ( not $passenger_type_map{ $passenger->{type} } ) {
+ die("Unknown passenger type: '$passenger->{type}'");
+ }
+ my $entry = {
+ typ => $passenger_type_map{ $passenger->{type} },
+ alter => [],
+ anzahl => 1
+ };
+ for my $discount ( @{ $passenger->{discounts} // [] } ) {
+ my ( $type, $class );
+ for my $num (qw(25 50 100)) {
+ if ( $discount eq "bc${num}" ) {
+ $type = "BAHNCARD${num}";
+ $class = 'KLASSE_2';
+ }
+ elsif ( $discount eq "bc${num}-first" ) {
+ $type = "BAHNCARD${num}";
+ $class = 'KLASSE_1';
+ }
}
- elsif ( $discount eq "bc${num}-first" ) {
- $type = "BAHNCARD${num}";
- $class = 'KLASSE_1';
+ if ($type) {
+ push(
+ @{ $entry->{ermaessigungen} },
+ {
+ art => $type,
+ klasse => $class,
+ }
+ );
}
}
- if ($type) {
- push(
- @{ $req->{reisende}[0]{ermaessigungen} },
+ if ( not @{ $entry->{ermaessigungen} // [] } ) {
+ $entry->{ermaessigungen} = [
{
- art => $type,
- klasse => $class,
+ art => 'KEINE_ERMAESSIGUNG',
+ klasse => 'KLASSENLOS'
}
- );
+ ];
}
+ push( @{ $req->{reisende} }, $entry );
}
$self->{strptime_obj} //= DateTime::Format::Strptime->new(
@@ -381,11 +407,15 @@ Default: de.
Only request connections using the modes of transit specified in I<arrayref>.
Default: ICE, EC_IC, IR, REGIONAL, SBAHN, BUS, SCHIFF, UBAHN, TRAM, ANRUFPFLICHTIG.
-=item B<discounts> => I<arrayref>
+=item B<passengers> => I<arrayref>
+
+Use passengers as defined by I<arrayref> when determining offer prices. Each
+entry describes a single person with a B<type> (string) and B<discounts>
+(arrayref). B<type> must be B<adult> (27 to 64 years old), B<junior> (15 to 26
+years old), or B<senior> (65 years or older). Supported discounts are: bc25,
+bc25-first, bc50, bc50-first, bc100, bc100-first.
-Consider discounts specified in I<arrayref> when determining offer prices.
-Supported items: bc25, bc25-first, bc50, bc50-first, bc100, bc100-first.
-Default: none.
+Default: single adult, no discounts.
=item B<user_agent> => I<user agent>