From e7edcfd9c675015073c914993fcf47ad4d83a640 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 18 Sep 2015 17:17:31 +0200 Subject: HAFAS stopfinder support --- index.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'index.pl') diff --git a/index.pl b/index.pl index 22dacd8..3c2c305 100644 --- a/index.pl +++ b/index.pl @@ -4,6 +4,7 @@ use Cache::File; use File::Slurp qw(read_file write_file); use List::MoreUtils qw(); use Travel::Status::DE::HAFAS; +use Travel::Status::DE::HAFAS::StopFinder; use Travel::Status::DE::IRIS; use Travel::Status::DE::IRIS::Stations; use 5.014; @@ -268,6 +269,25 @@ sub handle_request { } if ( not @results ) { + if ( $backend eq 'ris' ) { + my %db_service = Travel::Status::DE::HAFAS::get_service('DB'); + my $sf = Travel::Status::DE::HAFAS::StopFinder->new( + url => $db_service{stopfinder}, + input => $station, + ); + my @candidates + = map { [ "$_->{name} ($_->{id})", $_->{id} ] } $sf->results; + if ( @candidates > 1 + or ( @candidates == 1 and $candidates[0][1] ne $station ) ) + { + $self->render( + 'landingpage', + stationlist => \@candidates, + hide_opts => 0 + ); + return; + } + } if ( $backend eq 'iris' ) { my @candidates = map { [ "$_->[1] ($_->[0])", $_->[0] ] } Travel::Status::DE::IRIS::Stations::get_station($station); -- cgit v1.2.3