diff options
author | Daniel Friesel <derf@finalrewind.org> | 2015-07-29 20:11:43 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2015-07-29 20:11:43 +0200 |
commit | f78b589ffc5874106aa8af2d028d6602b2287ea0 (patch) | |
tree | f932cae7a45dcee7e6ca56b1d81531febcfac1ff | |
parent | de828666cfafcf2d767e67c5f0d568f9e6eb9be0 (diff) |
add service list and --service option (not 100% tested and documented yet)
-rwxr-xr-x | bin/efa-m | 38 | ||||
-rw-r--r-- | lib/Travel/Status/DE/EFA.pm | 76 |
2 files changed, 110 insertions, 4 deletions
@@ -18,10 +18,11 @@ use Travel::Status::DE::EFA; my $efa_url = 'http://efa.vrr.de/vrr/XSLT_DM_REQUEST'; my ( $date, $time, $input_type, $list_lines, $offset, $relative_times ); my ($full_routes); -my ( $filter_via, $track_via ); -my ( $timeout, $developer_mode ); -my ( @grep_lines, @grep_platforms, @grep_mots ); -my ( %edata, @edata_pre ); +my ( $filter_via, $track_via ); +my ( $timeout, $developer_mode ); +my ( @grep_lines, @grep_platforms, @grep_mots ); +my ( %edata, @edata_pre ); +my ( $list_services, $service ); @ARGV = map { decode( 'UTF-8', $_ ) } @ARGV; @@ -30,11 +31,13 @@ GetOptions( 'h|help' => sub { show_help(0) }, 'l|line=s@' => \@grep_lines, 'L|linelist' => \$list_lines, + 'list' => \$list_services, 'm|mot=s@' => \@grep_mots, 'o|offset=i' => \$offset, 'O|output=s@' => \@edata_pre, 'p|platform=s@' => \@grep_platforms, 'r|relative' => \$relative_times, + 's|service=s' => \$service, 't|time=s' => \$time, 'timeout=i' => \$timeout, 'u|efa-url=s' => \$efa_url, @@ -45,6 +48,10 @@ GetOptions( ) or show_help(1); +if ($list_services) { + show_services(); +} + if ( @ARGV != 2 ) { show_help(1); } @@ -74,6 +81,20 @@ if ($filter_via) { $full_routes = 1; } +if ($service) { + my $service_ref = first { lc( $_->{shortname} ) eq lc($service) } + Travel::Status::DE::EFA::get_efa_urls(); + if ( not $service_ref ) { + printf STDERR ( + "Error: Unknown service '%s'. See 'efa-m --list' for a " + . "list of supported service names\n", + $service + ); + exit 1; + } + $efa_url = $service_ref->{url}; +} + my $status = Travel::Status::DE::EFA->new( date => $date, developer_mode => $developer_mode, @@ -95,6 +116,15 @@ sub show_help { exit $code; } +sub show_services { + printf( "%-40s %-14s %s\n\n", 'service', 'abbr. (-s)', 'url (-u)' ); + for my $service ( Travel::Status::DE::EFA::get_efa_urls() ) { + printf( "%-40s %-14s %s\n", @{$service}{qw(name shortname url)} ); + } + + exit 0; +} + sub show_version { say "efa-m version ${VERSION}"; diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm index 73a05fb..53d2119 100644 --- a/lib/Travel/Status/DE/EFA.pm +++ b/lib/Travel/Status/DE/EFA.pm @@ -486,6 +486,67 @@ sub results { return @results; } +# static +sub get_efa_urls { + return ( + { + url => 'http://www.ding.eu/ding3/XSLT_DM_REQUEST', + name => 'Donau-Iller Nahverkehrsverbund', + shortname => 'DING', + }, + { + url => 'http://efa.ivb.at/ivb/XSLT_DM_REQUEST', + name => 'Innsbrucker Verkehrsbetriebe', + shortname => 'IVB', + }, + { + url => 'http://efa.svv-info.at/sbs/XSLT_DM_REQUEST', + name => 'Salzburger Verkehrsverbund', + shortname => 'SVV', + }, + { + url => 'http://efa.vor.at/wvb/XSLT_DM_REQUEST', + name => 'Verkehrsverbund Ost-Region', + shortname => 'VOR', + }, + { + url => 'http://efaneu.vmobil.at/vvv/XSLT_DM_REQUEST', + name => 'Vorarlberger Verkehrsverbund', + shortname => 'VVV', + }, + { + url => 'http://fahrplan.verbundlinie.at/stv/XSLT_DM_REQUEST', + name => 'Verkehrsverbund Steiermark', + shortname => 'Verbundlinie', + }, + { + url => 'http://www.linzag.at/static/XSLT_DM_REQUEST', + name => 'Linz AG', + shortname => 'LinzAG', + }, + { + url => 'http://212.114.197.7/vgnExt_oeffi/XML_DM_REQUEST', + name => 'Verkehrsverbund Grossraum Nuernberg', + shortname => 'VGN', + }, + { + url => 'http://efa.vrr.de/vrr/XSLT_DM_REQUEST', + name => 'Verkehrsverbund Rhein-Ruhr', + shortname => 'VRR', + }, + { + url => 'http://app.vrr.de/standard/XML_DM_REQUEST', + name => 'Verkehrsverbund Rhein-Ruhr (alternative)', + shortname => 'VRR2', + }, + { + url => 'http://www2.vvs.de/vvs/XSLT_DM_REQUEST', + name => 'Verkehrsverbund Stuttgart', + shortname => 'VVS', + }, + ); +} + 1; __END__ @@ -598,6 +659,21 @@ describing one line servicing the selected station. Returns a list of Travel::Status::DE::EFA::Result(3pm) objects, each one describing one departure. +=item Travel::Status::DE::EFA::get_efa_urls() + +Returns a list of known EFA entry points. Each list element is a hashref with +the following elements. + +=over + +=item B<url>: service URL as passed to B<efa_url> + +=item B<name>: Name of the entity operating this service + +=item B<shortname>: Short name of the entity + +=back + =back =head1 DIAGNOSTICS |