diff options
Diffstat (limited to 'lib/DBInfoscreen/Helper/Wagonorder.pm')
-rw-r--r-- | lib/DBInfoscreen/Helper/Wagonorder.pm | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/DBInfoscreen/Helper/Wagonorder.pm b/lib/DBInfoscreen/Helper/Wagonorder.pm index e843b54..5904d86 100644 --- a/lib/DBInfoscreen/Helper/Wagonorder.pm +++ b/lib/DBInfoscreen/Helper/Wagonorder.pm @@ -1,4 +1,5 @@ package DBInfoscreen::Helper::Wagonorder; + # Copyright (C) 2011-2020 Daniel Friesel # # SPDX-License-Identifier: BSD-2-Clause @@ -56,6 +57,47 @@ sub is_available_p { return $promise; } +sub has_umlauf_p { + my ( $self, $train_no ) = @_; + + my $promise = Mojo::Promise->new; + + my $url = "https://lib.finalrewind.org/dbdb/db_umlauf/${train_no}.png"; + my $cache = $self->{main_cache}; + + if ( my $content = $cache->get($url) ) { + if ( $content eq 'y' ) { + return $promise->resolve; + } + else { + return $promise->reject; + } + } + + $self->{user_agent}->request_timeout(5)->head_p( $url => $self->{header} ) + ->then( + sub { + my ($tx) = @_; + if ( $tx->result->is_success ) { + $cache->set( $url, 'y' ); + $promise->resolve; + } + else { + $cache->set( $url, 'n' ); + $promise->reject; + } + return; + } + )->catch( + sub { + $cache->set( $url, 'n' ); + $promise->reject; + return; + } + )->wait; + return $promise; +} + sub check_wagonorder_p { my ( $self, $train_no, $wr_link ) = @_; |