From 88b2cb36297ad2dcd661040b79a04c6fb34ed319 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 12 Sep 2015 00:41:16 +0200 Subject: support all known EFA entry points --- index.pl | 33 ++++++++++++++++++++++++++++++++- templates/main.html.ep | 5 ++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/index.pl b/index.pl index 9ed5c56..2eeb4be 100644 --- a/index.pl +++ b/index.pl @@ -6,6 +6,7 @@ use utf8; use DateTime; use DateTime::Format::Strptime; use Encode qw(decode); +use List::Util qw(first); use List::MoreUtils qw(any); use App::VRR::Fakedisplay; @@ -27,8 +28,12 @@ my %default = ( platform => q{}, ); +my @efa_services + = map { $_->{shortname} } Travel::Status::DE::EFA::get_efa_urls(); + sub get_results { my ( $backend, $city, $stop, $expiry ) = @_; + my $sub_backend; $expiry ||= 150; @@ -38,6 +43,16 @@ sub get_results { lock_level => Cache::File::LOCK_LOCAL(), ); + if ( $backend =~ m{ [.] }x ) { + ($sub_backend) = ( $backend =~ m{ [.] (.+) $ }x ); + + if ( not $sub_backend ~~ \@efa_services ) { + $sub_backend = undef; + $backend =~ s{ [.] (.+) $ }{}x; + } + } + say "$backend : $sub_backend"; + my $sstr = ("${backend} _ ${stop} _ ${city}"); $sstr =~ tr{a-zA-Z0-9}{_}c; @@ -67,7 +82,17 @@ sub get_results { ); } else { - $status = Travel::Status::DE::VRR->new( + my $efa_url = 'http://efa.vrr.de/vrr/XSLT_DM_REQUEST'; + if ($sub_backend) { + my $service + = first { lc( $_->{shortname} ) eq lc($sub_backend) } + Travel::Status::DE::EFA::get_efa_urls(); + if ($service) { + $efa_url = $service->{url}; + } + } + $status = Travel::Status::DE::EFA->new( + efa_url => $efa_url, place => $city, name => $stop, timeout => 3, @@ -479,6 +504,12 @@ sub render_image { return; } +helper 'efa_service_list' => sub { + my $self = shift; + + return @efa_services; +}; + get '/_redirect' => sub { my $self = shift; my $city = $self->param('city') // q{}; diff --git a/templates/main.html.ep b/templates/main.html.ep index 67a4c5b..cfe4cd2 100644 --- a/templates/main.html.ep +++ b/templates/main.html.ep @@ -146,7 +146,10 @@ other German transit networks.
backend
- %= select_field backend => [['EFA / VRR' => 'vrr'], ['DB (HAFAS)' => 'db'], ['ASEAG (URA)' => 'aseag']] + % my @efa_backends = map { ["$_ (EFA)" => "efa.$_"] } efa_service_list(); + % @efa_backends = map { $_->[1] } sort { $a->[0] cmp $b->[0] } + % map { [$_->[0], $_] } @efa_backends; + %= select_field backend => [['EFA / VRR' => 'vrr'], ['DB (HAFAS)' => 'db'], ['ASEAG (URA)' => 'aseag'], @efa_backends]
-- cgit v1.2.3