summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-09-14 15:55:14 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-09-14 15:55:14 +0200
commit52b55d2a5c982c4a56db7dfde4326eb195798c63 (patch)
tree70f7c033a8a8aa1fb388bc9302aae42ebde32de5
parentaaa3810ffba6e7908b5a5480fc55887d1879fcf3 (diff)
HAFAS/hafas-m: Add StopFinder support
-rwxr-xr-xbin/hafas-m13
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm34
2 files changed, 45 insertions, 2 deletions
diff --git a/bin/hafas-m b/bin/hafas-m
index ffefecd..72c7560 100755
--- a/bin/hafas-m
+++ b/bin/hafas-m
@@ -103,6 +103,16 @@ sub parse_mot_options {
}
}
+sub show_similar_stops {
+ my @candidates = $status->similar_stops;
+ if (@candidates) {
+ say 'You might want to try one of the following stops:';
+ for my $c (@candidates) {
+ printf( "%s (%s)\n", $c->{name}, $c->{id} );
+ }
+ }
+}
+
sub display_result {
my (@lines) = @_;
@@ -141,6 +151,9 @@ sub display_result {
if ( my $err = $status->errstr ) {
say STDERR "Request error: ${err}";
+ if ( $status->errcode and $status->errcode eq 'H730' ) {
+ show_similar_stops();
+ }
exit 2;
}
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index 61e3469..2a7bb11 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -11,6 +11,7 @@ use Carp qw(confess);
use LWP::UserAgent;
use POSIX qw(strftime);
use Travel::Status::DE::HAFAS::Result;
+use Travel::Status::DE::HAFAS::StopFinder;
use XML::LibXML;
our $VERSION = '1.05';
@@ -18,12 +19,14 @@ our $VERSION = '1.05';
my %hafas_instance = (
BVG => {
url => 'http://bvg.hafas.de/bin/stboard.exe',
+ stopfinder => 'http://bvg.hafas.de/bin/ajax-getstop.exe',
name => 'Berliner Verkehrsgesellschaft',
productbits => [qw[s u tram bus ferry ice regio ondemand]],
},
DB => {
- url => 'http://reiseauskunft.bahn.de/bin/bhftafel.exe',
- name => 'Deutsche Bahn',
+ url => 'http://reiseauskunft.bahn.de/bin/bhftafel.exe',
+ stopfinder => 'http://reiseauskunft.bahn.de/bin/ajax-getstop.exe',
+ name => 'Deutsche Bahn',
productbits =>
[qw[ice ic_ec d regio s bus ferry u tram ondemand x x x x]],
},
@@ -102,6 +105,7 @@ sub new {
developer_mode => $conf{developer_mode},
exclusive_mots => $conf{exclusive_mots},
excluded_mots => $conf{excluded_mots},
+ station => $conf{station},
post => {
input => $conf{station},
date => $date,
@@ -210,17 +214,43 @@ sub check_input_error {
= $err->getAttribute('text')
. ' (code '
. $err->getAttribute('code') . ')';
+ $self->{errcode} = $err->getAttribute('code');
}
return;
}
+sub errcode {
+ my ($self) = @_;
+
+ return $self->{errcode};
+}
+
sub errstr {
my ($self) = @_;
return $self->{errstr};
}
+sub similar_stops {
+ my ($self) = @_;
+
+ my $service = $self->{active_service};
+
+ if ( $service and exists $hafas_instance{$service}{stopfinder} ) {
+ my $sf = Travel::Status::DE::HAFAS::StopFinder->new(
+ url => $hafas_instance{$service}{stopfinder},
+ input => $self->{station},
+ );
+ if ( my $err = $sf->errstr ) {
+ $self->{errstr} = $err;
+ return;
+ }
+ return $sf->results;
+ }
+ return;
+}
+
sub results {
my ($self) = @_;
my $mode = $self->{post}->{boardType};