diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-12-11 21:36:41 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-12-11 21:36:41 +0100 |
commit | e6160d75de7a603ffba5c0489fc17fd240475961 (patch) | |
tree | 6dd89cb4a7329bfb6d802460420a0299e585de1a | |
parent | 875dd4e0b5773f2f52841d2effdfdd110b852aa0 (diff) |
show wagon order for regional trains too, if available1.11.3
-rwxr-xr-x | lib/Travelynx.pm | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 3bb33ea..51fe12f 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -1813,6 +1813,37 @@ sub startup { ); $self->helper( + 'has_wagonorder_p' => sub { + my ( $self, $ts, $train_no ) = @_; + my $api_ts = $ts->strftime('%Y%m%d%H%M'); + my $url + = "https://lib.finalrewind.org/dbdb/has_wagonorder/${train_no}/${api_ts}"; + my $cache = $self->app->cache_iris_main; + my $promise = Mojo::Promise->new; + + if ( my $content = $cache->get($url) ) { + if ( $content eq 'n' ) { + $promise->reject; + return $promise; + } + } + + $self->ua->request_timeout(5)->head_p($url)->then( + sub { + $cache->set( $url, 'y' ); + $promise->resolve; + } + )->catch( + sub { + $cache->set( $url, 'n' ); + $promise->reject; + } + )->wait; + return $promise; + } + ); + + $self->helper( 'get_wagonorder_p' => sub { my ( $self, $ts, $train_no ) = @_; my $api_ts = $ts->strftime('%Y%m%d%H%M'); @@ -2104,10 +2135,15 @@ sub startup { } )->wait; - if ( $train->type =~ m{[EI]C} and $train->sched_departure ) { - $self->get_wagonorder_p( $train->sched_departure, + if ( $train->sched_departure ) { + $self->has_wagonorder_p( $train->sched_departure, $train->train_no )->then( sub { + return $self->get_wagonorder_p( $train->sched_departure, + $train->train_no ); + } + )->then( + sub { my ($wagonorder) = @_; my $res = $db->select( 'in_transit', ['data'], |