Unverified Commit 2d9a5396 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Use bahn.de rather than bahnhof.de for departure board

bahn.de provides the journeyIDs needed for trip detail requests
parent 58396156
Loading
Loading
Loading
Loading
+2 −2
Changes for bin/dbris-m: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ elsif ( $opt{station} !~ m{ ^ \d+ $ }x ) {
	  = Travel::Status::DE::DBRIS->new( locationSearch => $opt{station} );
	for my $result ( $status->results ) {
		if ( defined $result->eva ) {
			$opt{station} = $result->eva;
			$opt{station} = $result;
			last;
		}
	}
@@ -172,7 +172,7 @@ if ( $opt{station} ) {
			: q{ } x ( $max_delay + 2 ),
			$result->line,
			$result->dest_name,
			$result->platform // $result->sched_platform
			$result->rt_platform // $result->platform // q{}
		);
	}
}
+18 −3
Changes for lib/Travel/Status/DE/DBRIS.pm: 18 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -48,9 +48,24 @@ sub new {

	my $req;

	if ( my $eva = $conf{station} ) {
	if ( my $station = $conf{station} ) {
		my $now = DateTime->now( time_zone => 'Europe/Berlin' );
		$req
		  = "https://www.bahnhof.de/api/boards/departures?evaNumbers=${eva}&duration=60&stationCategory=1&locale=de&sortBy=TIME";
		  = 'https://www.bahn.de/web/api/reiseloesung/abfahrten'
		  . '?datum='
		  . $now->strftime('%Y-%m-%d')
		  . '&zeit='
		  . $now->strftime('%H:%M:00')
		  . '&ortExtId='
		  . $station->{eva}
		  . '&ortId='
		  . $station->{id}
		  . '&mitVias=true&maxVias=8'
		  . '&verkehrsmittel[]=ICE&verkehrsmittel[]=EC_IC'
		  . '&verkehrsmittel[]=IR&verkehrsmittel[]=REGIONAL'
		  . '&verkehrsmittel[]=SBAHN&verkehrsmittel[]=BUS'
		  . '&verkehrsmittel[]=SCHIFF&verkehrsmittel[]=UBAHN'
		  . '&verkehrsmittel[]=TRAM&verkehrsmittel[]=ANRUFPFLICHTIG';
	}
	elsif ( my $gs = $conf{geoSearch} ) {
		my $lat = $gs->{latitude};
@@ -69,7 +84,7 @@ sub new {
	}

	$self->{strptime_obj} //= DateTime::Format::Strptime->new(
		pattern   => '%Y-%m-%dT%H:%M:%S%Z',
		pattern   => '%Y-%m-%dT%H:%M:%S',
		time_zone => 'Europe/Berlin',
	);

+21 −20
Changes for lib/Travel/Status/DE/DBRIS/Journey.pm: 21 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -9,47 +9,48 @@ use parent 'Class::Accessor';
our $VERSION = '0.01';

Travel::Status::DE::DBRIS::Journey->mk_ro_accessors(
	qw(type dep sched_dep rt_dep delay is_cancelled line stop_name stop_eva id admin_id journey_id sched_platform platform dest_name dest_eva route)
	qw(type dep sched_dep rt_dep delay is_cancelled line stop_eva journey_id platform rt_platform dest_name via)
);

sub new {
	my ( $obj, %opt ) = @_;

	my $json     = $opt{json}->[0];
	my $json     = $opt{json};
	my $strptime = $opt{strptime_obj};

	my $ref = {
		type                => $json->{type},
		line                => $json->{lineName},
		id                  => $json->{id},
		type        => $json->{verkehrmittel}{kurzText},
		line        => $json->{verkehrmittel}{mittelText},
		journey_id  => $json->{journeyID},
		admin_id            => $json->{administrationID},
		stop_eva            => $json->{stopPlace}{eva},
		stop_name           => $json->{stopPlace}{name},
		is_cancelled        => $json->{canceled},
		dest_name           => $json->{destination}{name},
		platform            => $json->{platform},
		sched_platform      => $json->{platformSchedule},
		dest_eva            => $json->{destination}{evaNumber},
		raw_route           => $json->{viaStops},
		raw_cancelled_route => $json->{canceledStopsAfterActualDestination},
		stop_eva    => $json->{bahnhofsId},
		dest_name   => $json->{terminus},
		platform    => $json->{gleis},
		rt_platform => $json->{ezGleis},
		via         => $json->{ueber},
	};

	bless( $ref, $obj );

	if ( $json->{timeSchedule} ) {
		$ref->{sched_dep} = $strptime->parse_datetime( $json->{timeSchedule} );
	if ( $json->{zeit} ) {
		$ref->{sched_dep} = $strptime->parse_datetime( $json->{zeit} );
	}
	if ( $json->{timeDelayed} ) {
		$ref->{rt_dep} = $strptime->parse_datetime( $json->{timeDelayed} );
	if ( $json->{ezZeit} ) {
		$ref->{rt_dep} = $strptime->parse_datetime( $json->{ezZeit} );
	}
	$ref->{dep} = $ref->{rt_dep} // $ref->{schd_dep};
	$ref->{dep} = $ref->{rt_dep} // $ref->{sched_dep};

	if ( $ref->{sched_dep} and $ref->{rt_dep} ) {
		$ref->{delay} = $ref->{rt_dep}->subtract_datetime( $ref->{sched_dep} )
		  ->in_units('minutes');
	}

	for my $message ( @{ $json->{meldungen} // [] } ) {
		if ( $message->{type} and $message->{type} eq 'HALT_AUSFALL' ) {
			$ref->{is_cancelled} = 1;
		}
		push( @{ $ref->{messages} }, $message );
	}

	return $ref;
}