From f12b977e9996439d8fc7d5987ca9581b07966a2d Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 18 Sep 2015 22:31:56 +0200 Subject: switch to HAFAS backend, also improved legacy / sub-backend support --- index.pl | 34 ++++++++++++++++------------------ templates/main.html.ep | 6 +++--- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/index.pl b/index.pl index c36d92e..f1d9fad 100644 --- a/index.pl +++ b/index.pl @@ -11,7 +11,7 @@ use List::Util qw(first); use List::MoreUtils qw(any); use App::VRR::Fakedisplay; -use Travel::Status::DE::DeutscheBahn; +use Travel::Status::DE::HAFAS; use Travel::Status::DE::ASEAG; use Travel::Status::DE::EFA; @@ -52,12 +52,19 @@ sub get_results { lock_level => Cache::File::LOCK_LOCAL(), ); - if ( $backend =~ m{ [.] }x ) { - ($sub_backend) = ( $backend =~ m{ [.] (.+) $ }x ); + # legacy values + if ( not defined $backend or $backend eq 'vrr' ) { + $backend = 'efa.VRR'; + } + + if ( $backend =~ s{ [.] (.+) $ }{}x ) { + $sub_backend = $1; - if ( not $sub_backend ~~ \@efa_services ) { - $sub_backend = undef; - $backend =~ s{ [.] (.+) $ }{}x; + if ( $backend eq 'efa' and not $sub_backend ~~ \@efa_services ) { + return { + results => [], + errstr => "efa sub-backend '$sub_backend' not supported" + }; } } @@ -72,18 +79,9 @@ sub get_results { } my $status; if ( $backend eq 'db' ) { - $status = Travel::Status::DE::DeutscheBahn->new( - station => "${stop}, ${city}", - mot => { - ice => 0, - ic_ec => 0, - d => 0, - nv => 0, - s => 1, - bus => 1, - u => 1, - tram => 1, - }, + $status = Travel::Status::DE::HAFAS->new( + station => "${stop}, ${city}", + excluded_mots => [qw[ice ic_ec d regio]], ); } elsif ( $backend eq 'aseag' ) { diff --git a/templates/main.html.ep b/templates/main.html.ep index 7dc9cb9..13dda0e 100644 --- a/templates/main.html.ep +++ b/templates/main.html.ep @@ -51,7 +51,7 @@ Data is cached for 1 minute. JSON format: % if (param('backend') and param('backend') eq 'db') { serialized -Travel::Status::DE::DeutscheBahn-objects, see the +Travel::Status::DE::HAFAS-objects, see the ::Result documentation % } @@ -186,8 +186,8 @@ v<%= $version %>
Backends:
Travel::Status::DE::ASEAG v<%= $Travel::Status::DE::ASEAG::VERSION %>
-Travel::Status::DE::DeutscheBahn -v<%= $Travel::Status::DE::DeutscheBahn::VERSION %>
+Travel::Status::DE::HAFAS +v<%= $Travel::Status::DE::HAFAS::VERSION %>
Travel::Status::DE::EFA v<%= $Travel::Status::DE::EFA::VERSION %>
-- cgit v1.2.3