summaryrefslogtreecommitdiff
path: root/lib/Travel/Routing/DE
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 /lib/Travel/Routing/DE
parent042edb977fb7d5827af3bce844a8c00bd1442bcb (diff)
Add support for language selection
Diffstat (limited to 'lib/Travel/Routing/DE')
-rw-r--r--lib/Travel/Routing/DE/DBRIS.pm24
1 files changed, 12 insertions, 12 deletions
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 ) {