diff options
author | Daniel Friesel <derf@finalrewind.org> | 2015-09-12 00:41:16 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2015-09-12 00:41:16 +0200 |
commit | 88b2cb36297ad2dcd661040b79a04c6fb34ed319 (patch) | |
tree | 0f7b32acf71ae5598793fd942cb9283c354bc1e3 | |
parent | 65634e360e73592369616093ce5b49da38f28796 (diff) |
support all known EFA entry points0.09
-rw-r--r-- | index.pl | 33 | ||||
-rw-r--r-- | templates/main.html.ep | 5 |
2 files changed, 36 insertions, 2 deletions
@@ -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. <div class="field"> <div class="desc">backend</div> <div> - %= 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] </div> </div> <div class="field"> |