Unverified Commit 3689a690 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add support for language selection

parent 042edb97
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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,
);
+12 −12
Original line number Diff line number Diff line
@@ -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;
@@ -215,13 +220,8 @@ sub post_with_cache {
	my $reply = $self->{ua}->post(
		$url,
		Accept            => 'application/json',
		'Accept-Language' => $self->{language},
		'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,
	);