From 6526ae6a64c14f9d64a791b778b157f502a5aa0a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 29 Jan 2023 17:40:27 +0100 Subject: add hafas (bus, ubahn, tram) support --- lib/DBInfoscreen/Helper/HAFAS.pm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'lib/DBInfoscreen/Helper/HAFAS.pm') diff --git a/lib/DBInfoscreen/Helper/HAFAS.pm b/lib/DBInfoscreen/Helper/HAFAS.pm index a6769aa..6111a5b 100644 --- a/lib/DBInfoscreen/Helper/HAFAS.pm +++ b/lib/DBInfoscreen/Helper/HAFAS.pm @@ -181,7 +181,19 @@ sub get_route_timestamps_p { my $promise = Mojo::Promise->new; my $now = DateTime->now( time_zone => 'Europe/Berlin' ); - if ( $opt{train} ) { + my $hafas_promise; + + if ( $opt{trip_id} ) { + $hafas_promise = Travel::Status::DE::HAFAS->new_p( + journey => { + id => $opt{trip_id}, + }, + cache => $self->{realtime_cache}, + promise => 'Mojo::Promise', + user_agent => $self->{user_agent}->request_timeout(10) + ); + } + elsif ( $opt{train} ) { $opt{date_yy} = $opt{train}->start->strftime('%d.%m.%y'); $opt{date_yyyy} = $opt{train}->start->strftime('%d.%m.%Y'); $opt{train_req} = $opt{train}->type . ' ' . $opt{train}->train_no; @@ -193,7 +205,7 @@ sub get_route_timestamps_p { $opt{date_yyyy} = $now->strftime('%d.%m.%Y'); } - $self->trainsearch_p(%opt)->then( + $hafas_promise //= $self->trainsearch_p(%opt)->then( sub { my ($trainsearch_result) = @_; my $trip_id = $trainsearch_result->{trip_id}; @@ -208,7 +220,9 @@ sub get_route_timestamps_p { user_agent => $self->{user_agent}->request_timeout(10) ); } - )->then( + ); + + $hafas_promise->then( sub { my ($hafas) = @_; my $journey = $hafas->result; -- cgit v1.2.3