summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-12-23 16:54:59 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2024-12-23 16:54:59 +0100
commit2d9a53966da3abee99dd03d94cd39d0043cbb01a (patch)
tree98dcc41cadf8edea3bcdebeccaceccb8f54b60b8
parent583961562fa23374de21dfac3ec7e3d161db2207 (diff)
Use bahn.de rather than bahnhof.de for departure board
bahn.de provides the journeyIDs needed for trip detail requests
-rwxr-xr-xbin/dbris-m4
-rw-r--r--lib/Travel/Status/DE/DBRIS.pm21
-rw-r--r--lib/Travel/Status/DE/DBRIS/Journey.pm43
3 files changed, 42 insertions, 26 deletions
diff --git a/bin/dbris-m b/bin/dbris-m
index d4de7e7..f8dd9f7 100755
--- a/bin/dbris-m
+++ b/bin/dbris-m
@@ -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{}
);
}
}
diff --git a/lib/Travel/Status/DE/DBRIS.pm b/lib/Travel/Status/DE/DBRIS.pm
index 4deba94..2f17e90 100644
--- a/lib/Travel/Status/DE/DBRIS.pm
+++ b/lib/Travel/Status/DE/DBRIS.pm
@@ -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',
);
diff --git a/lib/Travel/Status/DE/DBRIS/Journey.pm b/lib/Travel/Status/DE/DBRIS/Journey.pm
index d82b21f..6e420f4 100644
--- a/lib/Travel/Status/DE/DBRIS/Journey.pm
+++ b/lib/Travel/Status/DE/DBRIS/Journey.pm
@@ -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},
- 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},
+ type => $json->{verkehrmittel}{kurzText},
+ line => $json->{verkehrmittel}{mittelText},
+ journey_id => $json->{journeyID},
+ 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;
}