summaryrefslogtreecommitdiff
path: root/bin/dbris
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-02-02 18:25:47 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-02-02 18:25:47 +0100
commit7cb9cb9836af5db19568886f9804b7032d27312f (patch)
tree5327fea154cda3a6fbad33241f1d1c61f08273f1 /bin/dbris
parent43f9af3c356a0607e3fcc121311f11bf57746e2b (diff)
add ticket offer API client and --with-offers option
Diffstat (limited to 'bin/dbris')
-rwxr-xr-xbin/dbris27
1 files changed, 26 insertions, 1 deletions
diff --git a/bin/dbris b/bin/dbris
index 7d06b64..9c0eb54 100755
--- a/bin/dbris
+++ b/bin/dbris
@@ -16,9 +16,9 @@ use Travel::Routing::DE::DBRIS;
my ( $date, $time, $arrival, $from, $to, $language );
my $mots;
+my ( $show_jid, $show_full_route, $show_offers );
my ( $first_class, $passengers );
my ( $developer_mode, $verbose );
-my ( $show_jid, $show_full_route );
my ( $json_output, $raw_json_output );
my $use_cache = 1;
my $cache;
@@ -55,6 +55,7 @@ GetOptions(
'j|with-jid' => \$show_jid,
'm|modes-of-transit=s' => \$mots,
'l|language=s' => \$language,
+ 'o|with-offers' => \$show_offers,
'p|passengers=s' => \$passengers,
't|time=s' => \$time,
'v|verbose' => \$verbose,
@@ -369,6 +370,30 @@ for my $connection ( $ris->connections ) {
$header,
);
+ if ($show_offers) {
+ my $offers_req = Travel::Routing::DE::DBRIS->new(
+ developer_mode => $developer_mode,
+ offers => {
+ recon => $connection->recon,
+ },
+ passengers => $opt{passengers},
+ first_class => $opt{first_class},
+ );
+ if ( my $err = $offers_req->errstr ) {
+ say STDERR "Request error while looking up offers: ${err}";
+ }
+ for my $offer ($offers_req->offers) {
+ printf('- %5.2f %s %s', $offer->price, $offer->price_unit =~ s{EUR}{€}r, $offer->name);
+ if ($first_class and $offer->class == 2 or not $first_class and $offer->class == 1) {
+ printf(" %d. Klasse", $offer->class);
+ }
+ if (scalar $offer->conditions) {
+ printf(' (%s)', join(q{ · }, map { $_->{textKurz} } $offer->conditions));
+ }
+ say q{};
+ }
+ }
+
if ($verbose) {
for my $note ( $connection->notes ) {
printf( "| %s (%s)\n", $note->{value}, $note->{key} );