summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-01-19 07:54:48 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-01-19 07:54:48 +0100
commit3689a6901a16db29cf19a1809ff8bc2724fd8253 (patch)
tree4b6b6615f6148d9787873c9e751b15ee838eaf09
parent042edb977fb7d5827af3bce844a8c00bd1442bcb (diff)
Add support for language selection
-rwxr-xr-xbin/dbris4
-rw-r--r--lib/Travel/Routing/DE/DBRIS.pm24
2 files changed, 15 insertions, 13 deletions
diff --git a/bin/dbris b/bin/dbris
index 24b5203..6640c7c 100755
--- a/bin/dbris
+++ b/bin/dbris
@@ -14,7 +14,7 @@ use List::Util qw(max);
use Travel::Status::DE::DBRIS;
use Travel::Routing::DE::DBRIS;
-my ( $date, $time, $from, $to );
+my ( $date, $time, $from, $to, $language );
my $mots;
my $discounts;
my $developer_mode;
@@ -39,6 +39,7 @@ GetOptions(
'h|help' => sub { show_help(0) },
'f|full-route' => \$show_full_route,
'm|modes-of-transit=s' => \$mots,
+ 'l|language=s' => \$language,
't|time=s' => \$time,
'V|version' => \&show_version,
'cache!' => \$use_cache,
@@ -94,6 +95,7 @@ sub get_stop {
my %opt = (
from => get_stop($from_raw),
to => get_stop($to_raw),
+ language => $language,
cache => $cache,
developer_mode => $developer_mode,
);
diff --git a/lib/Travel/Routing/DE/DBRIS.pm b/lib/Travel/Routing/DE/DBRIS.pm
index 618e2b4..1e76b03 100644
--- a/lib/Travel/Routing/DE/DBRIS.pm
+++ b/lib/Travel/Routing/DE/DBRIS.pm
@@ -36,11 +36,14 @@ sub new {
$ua->env_proxy;
}
+ # Supported Languages: de cs da en es fr it nl pl
+
my $self = {
cache => $conf{cache},
developer_mode => $conf{developer_mode},
from => $conf{from},
to => $conf{to},
+ language => $conf{language} // 'de',
ua => $ua,
};
@@ -53,6 +56,10 @@ sub new {
@mots = @{ $conf{modes_of_transit} // [] };
}
+ my $req_url
+ = $self->{language} eq 'de'
+ ? 'https://www.bahn.de/web/api/angebote/fahrplan'
+ : 'https://int.bahn.de/web/api/angebote/fahrplan';
my $req = {
abfahrtsHalt => $conf{from}->id,
ankunftsHalt => $conf{to}->id,
@@ -133,9 +140,7 @@ sub new {
say "requesting $req_str";
}
- my ( $content, $error )
- = $self->post_with_cache(
- 'https://www.bahn.de/web/api/angebote/fahrplan', $req_str );
+ my ( $content, $error ) = $self->post_with_cache( $req_url, $req_str );
if ($error) {
$self->{errstr} = $error;
@@ -214,15 +219,10 @@ sub post_with_cache {
my $reply = $self->{ua}->post(
$url,
- Accept => 'application/json',
- 'Content-Type' => 'application/json; charset=utf-8',
- Origin => 'https://www.bahn.de',
- Referer => 'https://www.bahn.de/buchung/fahrplan/suche',
- 'Sec-Fetch-Dest' => 'empty',
- 'Sec-Fetch-Mode' => 'cors',
- 'Sec-Fetch-Site' => 'same-origin',
- TE => 'trailers',
- Content => $req,
+ Accept => 'application/json',
+ 'Accept-Language' => $self->{language},
+ 'Content-Type' => 'application/json; charset=utf-8',
+ Content => $req,
);
if ( $reply->is_error ) {