HAFAS: Use locationSearch rather than similar_stops_p

locationSearch uses mgate.exe, just like the regular departure board.
similar_stops_p relies on ajax-getstop.exe which may become unavailable sooner
rather than later.
This commit is contained in:
Birte Kristina Friesel 2023-11-01 18:44:00 +01:00
parent 0b1de41366
commit 6364751eb1
No known key found for this signature in database
GPG key ID: 19E6E524EBB177BA
2 changed files with 18 additions and 10 deletions

View file

@ -1105,23 +1105,20 @@ sub station {
} }
elsif ( $use_hafas and $status and $status->errcode eq 'LOCATION' ) elsif ( $use_hafas and $status and $status->errcode eq 'LOCATION' )
{ {
$status->similar_stops_p->then( $self->hafas->search_location_p( query => $station )->then(
sub { sub {
my @suggestions = @_; my ($hafas2) = @_;
my @suggestions = $hafas2->results;
if ( @suggestions == 1 ) { if ( @suggestions == 1 ) {
$self->redirect_to( $self->redirect_to(
'/s/' . $suggestions[0]->{id} . '?hafas=1' ); '/s/' . $suggestions[0]->eva . '?hafas=1' );
} }
else { else {
$self->render( $self->render(
'disambiguation', 'disambiguation',
suggestions => [ suggestions => [
map { map { { name => $_->name, eva => $_->eva } }
{ @suggestions
name => $_->{name},
eva => $_->{id}
}
} @suggestions
], ],
status => 300, status => 300,
); );
@ -1133,7 +1130,7 @@ sub station {
$self->render( $self->render(
'exception', 'exception',
exception => exception =>
"StopFinder threw '$err2' when handling '$err'", "locationSearch threw '$err2' when handling '$err'",
status => 502 status => 502
); );
} }

View file

@ -98,6 +98,17 @@ sub get_departures_p {
); );
} }
sub search_location_p {
my ( $self, %opt ) = @_;
return Travel::Status::DE::HAFAS->new_p(
locationSearch => $opt{query},
cache => $self->{realtime_cache},
promise => 'Mojo::Promise',
user_agent => $self->{user_agent}->request_timeout(5),
);
}
sub get_journey_p { sub get_journey_p {
my ( $self, %opt ) = @_; my ( $self, %opt ) = @_;