diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-06-01 11:52:42 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-06-01 11:52:42 +0200 |
commit | d701442306ebdac5d7d6a865003a1a8a1f6ac334 (patch) | |
tree | 3b617a698c15126fc9b5022f6ca691f60a06f1c9 | |
parent | 102f6ddf7f57cc92dc8462b9fad80900ff8e671f (diff) |
Set arrival time via HAFAS if not available from IRIS
-rwxr-xr-x | lib/Travelynx.pm | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 3bc9e3c..7b87b99 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -530,7 +530,8 @@ sub startup { my $now = DateTime->now( time_zone => 'Europe/Berlin' ); my $journey - = $db->select( 'in_transit', '*', { user_id => $uid } )->hash; + = $db->select( 'in_transit', '*', { user_id => $uid } ) + ->expand->hash; my ($train) = first { $_->train_id eq $train_id } @{ $status->{results} }; @@ -568,6 +569,31 @@ sub startup { if ( not( defined $train or $force ) ) { $self->run_hook( $uid, 'update' ); + + # Arrival time via IRIS is unknown, try falling back to HAFAS + if ( my $station_data + = first { $_->[0] eq $station } @{ $journey->{route} } ) + { + $station_data = $station_data->[1]; + if ( $station_data->{sched_arr} ) { + my $sched_arr + = epoch_to_dt( $station_data->{sched_arr} ); + my $rt_arr = $sched_arr->clone; + if ( $station_data->{adelay} + and $station_data->{adelay} =~ m{^\d+$} ) + { + $rt_arr->add( minutes => $station_data->{adelay} ); + } + $db->update( + 'in_transit', + { + sched_arrival => $sched_arr, + real_arrival => $rt_arr + }, + { user_id => $uid } + ); + } + } return ( 1, undef ); } |