diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-01-04 22:51:59 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-01-04 22:51:59 +0100 |
commit | 3d22c00120518f8c5207fe1049a00506091cd43c (patch) | |
tree | 5b252917e282970663309467e75c150149ac55cc /lib/DBInfoscreen/Controller/Stationboard.pm | |
parent | d8d8d53efd8e5d81e648e264a0b45e4e151c5277 (diff) |
show train route on map2.5.0
Diffstat (limited to 'lib/DBInfoscreen/Controller/Stationboard.pm')
-rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 9ebaca4..e32e78d 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -117,6 +117,46 @@ sub check_wagonorder_with_wings { return; } +sub get_hafas_trip_id { + my ( $ua, $cache, $train ) = @_; + + my $eva = $train->station_uic; + my $dep_ts = DateTime->now( time_zone => 'Europe/Berlin' ); + if ( $train->sched_departure ) { + $dep_ts = $train->sched_departure->epoch; + } + elsif ( $train->sched_arrival ) { + $dep_ts = $train->sched_arrival->epoch; + } + + $ua->request_timeout(2); + my $res + = $ua->get( +"https://2.db.transport.rest/stations/${eva}/departures?duration=5&when=$dep_ts" + )->result; + if ( $res->is_error ) { + return; + } + + my $json = decode_json( $res->body ); + + #say "looking for " . $train->train_no; + for my $result ( @{$json} ) { + my $trip_id = $result->{tripId}; + my $fahrt = $result->{line}{fahrtNr}; + #say "checking $fahrt"; + if ( $result->{line} and $result->{line}{fahrtNr} == $train->train_no ) + { + #say "Trip ID is $trip_id"; + return $trip_id; + } + else { + #say "unmatched Trip ID $trip_id"; + } + } + return; +} + sub check_wagonorder { my ( $ua, $cache, $train_no, $wr_link ) = @_; @@ -985,6 +1025,10 @@ sub handle_request { ) ]; + $departures[-1]{trip_id} + = get_hafas_trip_id( $self->ua, $self->app->cache_iris_main, + $result ); + if ( $departures[-1]{wr_link} and not check_wagonorder_with_wings( |