Commit 52b55d2a authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

HAFAS/hafas-m: Add StopFinder support

parent aaa3810f
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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;
}

+32 −2
Original line number Diff line number Diff line
@@ -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,11 +19,13 @@ 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',
		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};