summaryrefslogtreecommitdiff
path: root/lib/Travelynx
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-02-06 12:31:35 +0100
committerDaniel Friesel <derf@finalrewind.org>2021-02-06 12:31:35 +0100
commit9223ba5fa1a3ab203bba1fb54e9d2a5772f0b0d8 (patch)
tree2c586b39843e6dc14deb5f9b753d8e1df3b3f149 /lib/Travelynx
parent5b1841cccefc74b8fa3b523b3a5b5359a9e39c6d (diff)
fall back to apps-bahn if ist-wr does not know about a train1.19.5
Diffstat (limited to 'lib/Travelynx')
-rw-r--r--lib/Travelynx/Helper/DBDB.pm23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/Travelynx/Helper/DBDB.pm b/lib/Travelynx/Helper/DBDB.pm
index 916b4cb..4baf3ed 100644
--- a/lib/Travelynx/Helper/DBDB.pm
+++ b/lib/Travelynx/Helper/DBDB.pm
@@ -1,4 +1,5 @@
package Travelynx::Helper::DBDB;
+
# Copyright (C) 2020 Daniel Friesel
#
# SPDX-License-Identifier: AGPL-3.0-or-later
@@ -34,21 +35,22 @@ sub has_wagonorder_p {
my $promise = Mojo::Promise->new;
if ( my $content = $cache->get($url) ) {
- if ( $content eq 'y' ) {
- return $promise->resolve;
- }
- elsif ( $content eq 'n' ) {
+ if ( $content eq 'n' ) {
return $promise->reject;
}
+ else {
+ return $promise->resolve($content);
+ }
}
- $self->{user_agent}->request_timeout(5)->head_p( $url => $self->{header} )
+ $self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} )
->then(
sub {
my ($tx) = @_;
if ( $tx->result->is_success ) {
- $cache->set( $url, 'y' );
- $promise->resolve;
+ my $body = $tx->result->body;
+ $cache->set( $url, $body );
+ $promise->resolve($body);
}
else {
$cache->set( $url, 'n' );
@@ -67,11 +69,16 @@ sub has_wagonorder_p {
}
sub get_wagonorder_p {
- my ( $self, $ts, $train_no ) = @_;
+ my ( $self, $api, $ts, $train_no ) = @_;
my $api_ts = $ts->strftime('%Y%m%d%H%M');
my $url
= "https://ist-wr.noncd.db.de/wagenreihung/1.0/${train_no}/${api_ts}";
+ if ( $api !~ m{i} and $api =~ m{a} ) {
+ $url
+ = "https://www.apps-bahn.de/wr/wagenreihung/1.0/${train_no}/${api_ts}";
+ }
+
my $cache = $self->{cache};
my $promise = Mojo::Promise->new;