summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/efa-m33
-rw-r--r--lib/Travel/Status/DE/EFA.pm162
2 files changed, 94 insertions, 101 deletions
diff --git a/bin/efa-m b/bin/efa-m
index 769960a..532843f 100755
--- a/bin/efa-m
+++ b/bin/efa-m
@@ -13,14 +13,15 @@ use Getopt::Long qw(:config no_ignore_case bundling);
use List::Util qw(first max none);
use Travel::Status::DE::EFA;
-my $efa_url = 'https://efa.vrr.de/vrr/XSLT_DM_REQUEST';
+my $service = 'VRR';
+my $efa_url;
my $efa_encoding;
my ( $date, $time, $input_type, $list_lines, $offset, $relative_times );
my ( $full_routes, $filter_via );
my ( $timeout, $developer_mode );
my ( @grep_lines, @grep_platforms, @grep_mots );
my ( %edata, @edata_pre );
-my ( $list_services, $service, $discover_and_print, $discover );
+my ( $list_services, $discover_and_print, $discover );
my $efa;
@ARGV = map { decode( 'UTF-8', $_ ) } @ARGV;
@@ -88,9 +89,11 @@ 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 ($efa_url) {
+ $service = undef;
+}
+elsif ($service) {
+ my $service_ref = Travel::Status::DE::EFA::get_service($service);
if ( not $service_ref ) {
printf STDERR (
"Error: Unknown service '%s'. See 'efa-m --list' for a "
@@ -99,16 +102,17 @@ if ($service) {
);
exit 1;
}
- $efa_url = $service_ref->{url};
$efa_encoding = $service_ref->{encoding};
+ $efa_url = undef;
}
-sub new_efa_by_url {
- my ($url) = @_;
+sub new_efa {
+ my ( $s, $u ) = @_;
my $res = Travel::Status::DE::EFA->new(
+ service => $s,
+ efa_url => $u,
date => $date,
developer_mode => $developer_mode,
- efa_url => $url,
efa_encoding => $efa_encoding,
full_routes => $full_routes,
place => $place,
@@ -371,7 +375,7 @@ sub show_results {
if ( $discover or $discover_and_print ) {
for my $service_ref ( Travel::Status::DE::EFA::get_efa_urls() ) {
- $efa = new_efa_by_url( $service_ref->{url} );
+ $efa = new_efa( $service_ref->{shortname} );
if ( $efa and not $efa->errstr ) {
if ($discover_and_print) {
last;
@@ -388,7 +392,7 @@ if ( $discover or $discover_and_print ) {
}
}
-$efa = new_efa_by_url($efa_url);
+$efa = new_efa( $service, $efa_url );
if ( my $err = $efa->errstr ) {
say STDERR "Request error: ${err}";
@@ -571,13 +575,6 @@ B<--list> option for a list of services.
Show departures starting at I<time> instead of now.
-=item B<-u>, B<--efa-url> I<url>
-
-URL to the EFA entry point, defaults to
-L<http://efa.vrr.de/vrr/XSLT_DM_REQUEST>. Depending on your location, some
-I<url>s may contain more specific data than others. See
-Travel::Status::DE::EFA(3pm) and the B<--list> option for alternatives.
-
=item B<--timeout> I<seconds>
Set timeout for HTTP requests. Default: 10 seconds. Set to 0 or a negative
diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm
index 64ba297..b61acbc 100644
--- a/lib/Travel/Status/DE/EFA.pm
+++ b/lib/Travel/Status/DE/EFA.pm
@@ -16,6 +16,73 @@ use Travel::Status::DE::EFA::Stop;
use LWP::UserAgent;
use XML::LibXML;
+my %efa_instance = (
+ BSVG => {
+ url => 'https://bsvg.efa.de/bsvagstd/XML_DM_REQUEST',
+ name => 'Braunschweiger Verkehrs-GmbH',
+ },
+ DING => {
+ url => 'https://www.ding.eu/ding3/XSLT_DM_REQUEST',
+ name => 'Donau-Iller Nahverkehrsverbund',
+ },
+ KVV => {
+ url => 'https://projekte.kvv-efa.de/sl3-alone/XSLT_DM_REQUEST',
+ name => 'Karlsruher Verkehrsverbund',
+ },
+ LinzAG => {
+ url => 'https://www.linzag.at/static/XSLT_DM_REQUEST',
+ name => 'Linz AG',
+ encoding => 'iso-8859-15',
+ },
+ MVV => {
+ url => 'https://efa.mvv-muenchen.de/mobile/XSLT_DM_REQUEST',
+ name => 'Münchner Verkehrs- und Tarifverbund',
+ },
+ NVBW => {
+ url => 'https://www.efa-bw.de/nvbw/XSLT_DM_REQUEST',
+ name => 'Nahverkehrsgesellschaft Baden-Württemberg',
+ },
+ VAG => {
+ url => 'https://efa.vagfr.de/vagfr3/XSLT_DM_REQUEST',
+ name => 'Freiburger Verkehrs AG',
+ },
+ VGN => {
+ url => 'https://efa.vgn.de/vgnExt_oeffi/XML_DM_REQUEST',
+ name => 'Verkehrsverbund Grossraum Nuernberg',
+ },
+
+ # HTTPS: certificate verification fails
+ VMV => {
+ url => 'http://efa.vmv-mbh.de/vmv/XML_DM_REQUEST',
+ name => 'Verkehrsgesellschaft Mecklenburg-Vorpommern',
+ },
+ VRN => {
+ url => 'https://www.vrn.de/mngvrn//XML_DM_REQUEST',
+ name => 'Verkehrsverbund Rhein-Neckar',
+ },
+ VRR => {
+ url => 'https://efa.vrr.de/vrr/XSLT_DM_REQUEST',
+ name => 'Verkehrsverbund Rhein-Ruhr',
+ },
+ VRR2 => {
+ url => 'https://app.vrr.de/standard/XML_DM_REQUEST',
+ name => 'Verkehrsverbund Rhein-Ruhr (alternative)',
+ },
+ VRR3 => {
+ url => 'https://efa.vrr.de/rbgstd3/XML_DM_REQUEST',
+ name => 'Verkehrsverbund Rhein-Ruhr (alternative alternative)',
+ },
+ VVO => {
+ url => 'https://efa.vvo-online.de/VMSSL3/XSLT_DM_REQUEST',
+ name => 'Verkehrsverbund Oberelbe',
+ },
+ VVS => {
+ url => 'https://www2.vvs.de/vvs/XSLT_DM_REQUEST',
+ name => 'Verkehrsverbund Stuttgart',
+ },
+
+);
+
sub new_p {
my ( $class, %opt ) = @_;
my $promise = $opt{promise}->new;
@@ -105,8 +172,12 @@ sub new {
confess('type must be stop, stopID, address, or poi');
}
+ if ( $opt{service} and exists $efa_instance{ $opt{service} } ) {
+ $opt{efa_url} = $efa_instance{ $opt{service} }{url};
+ }
+
if ( not $opt{efa_url} ) {
- confess('efa_url is mandatory');
+ confess('service or efa_url must be specified');
}
## no critic (RegularExpressions::ProhibitUnusedCapture)
@@ -630,89 +701,14 @@ sub results {
# static
sub get_efa_urls {
+ return map {
+ { %{ $efa_instance{$_} }, shortname => $_ }
+ } sort keys %efa_instance;
+}
- # sorted lexically by shortname
- return (
- {
- url => 'https://bsvg.efa.de/bsvagstd/XML_DM_REQUEST',
- name => 'Braunschweiger Verkehrs-GmbH',
- shortname => 'BSVG',
- },
- {
- url => 'https://www.ding.eu/ding3/XSLT_DM_REQUEST',
- name => 'Donau-Iller Nahverkehrsverbund',
- shortname => 'DING',
- },
- {
- url => 'https://projekte.kvv-efa.de/sl3-alone/XSLT_DM_REQUEST',
- name => 'Karlsruher Verkehrsverbund',
- shortname => 'KVV',
- },
- {
- url => 'https://www.linzag.at/static/XSLT_DM_REQUEST',
- name => 'Linz AG',
- shortname => 'LinzAG',
- encoding => 'iso-8859-15',
- },
- {
- url => 'https://efa.mvv-muenchen.de/mobile/XSLT_DM_REQUEST',
- name => 'Münchner Verkehrs- und Tarifverbund',
- shortname => 'MVV',
- },
- {
- url => 'https://www.efa-bw.de/nvbw/XSLT_DM_REQUEST',
- name => 'Nahverkehrsgesellschaft Baden-Württemberg',
- shortname => 'NVBW',
- },
- {
- url => 'https://efa.vagfr.de/vagfr3/XSLT_DM_REQUEST',
- name => 'Freiburger Verkehrs AG',
- shortname => 'VAG',
- },
- {
- url => 'https://efa.vgn.de/vgnExt_oeffi/XML_DM_REQUEST',
- name => 'Verkehrsverbund Grossraum Nuernberg',
- shortname => 'VGN',
- },
-
- # HTTPS: certificate verification fails
- {
- url => 'http://efa.vmv-mbh.de/vmv/XML_DM_REQUEST',
- name => 'Verkehrsgesellschaft Mecklenburg-Vorpommern',
- shortname => 'VMV',
- },
- {
- url => 'https://www.vrn.de/mngvrn//XML_DM_REQUEST',
- name => 'Verkehrsverbund Rhein-Neckar',
- shortname => 'VRN',
- },
- {
- url => 'https://efa.vrr.de/vrr/XSLT_DM_REQUEST',
- name => 'Verkehrsverbund Rhein-Ruhr',
- shortname => 'VRR',
- },
- {
- url => 'https://app.vrr.de/standard/XML_DM_REQUEST',
- name => 'Verkehrsverbund Rhein-Ruhr (alternative)',
- shortname => 'VRR2',
- },
- {
- url => 'https://efa.vrr.de/rbgstd3/XML_DM_REQUEST',
- name => 'Verkehrsverbund Rhein-Ruhr (alternative alternative)',
- shortname => 'VRR3',
- },
- {
- url => 'https://efa.vvo-online.de/VMSSL3/XSLT_DM_REQUEST',
- name => 'Verkehrsverbund Oberelbe',
- shortname => 'VVO',
- },
- {
- url => 'https://www2.vvs.de/vvs/XSLT_DM_REQUEST',
- name => 'Verkehrsverbund Stuttgart',
- shortname => 'VVS',
- },
-
- );
+sub get_service {
+ my ($service) = @_;
+ return $efa_instance{$service};
}
1;