summaryrefslogtreecommitdiff
path: root/bin/hafas
diff options
context:
space:
mode:
Diffstat (limited to 'bin/hafas')
-rwxr-xr-xbin/hafas82
1 files changed, 59 insertions, 23 deletions
diff --git a/bin/hafas b/bin/hafas
index 86cac23..d7dc9d3 100755
--- a/bin/hafas
+++ b/bin/hafas
@@ -3,7 +3,7 @@ use strict;
use warnings;
use 5.014;
-our $VERSION = '0.06';
+our $VERSION = '0.10';
use utf8;
use DateTime;
@@ -70,17 +70,29 @@ GetOptions(
) or show_help(1);
if ($list_services) {
- printf( "%-40s %-14s %s\n\n", 'operator', 'abbr. (-s)', 'languages (-l)' );
+ printf(
+ "%-40s %-14s %-15s %s\n\n",
+ 'operator', 'abbr. (-s)', 'languages (-l)',
+ 'time zone'
+ );
for my $service ( Travel::Routing::DE::HAFAS::get_services() ) {
+ if ( $service->{shortname} eq 'DB' ) {
+ next;
+ }
printf(
- "%-40s %-14s %s\n",
- @{$service}{qw(name shortname)},
- join( q{ }, @{ $service->{languages} // [] } )
+ "%-40s%1s %-14s %-15s %s\n",
+ $service->{name},
+ $service->{geoip_lock} ? q{!} : q{ },
+ $service->{shortname},
+ join( q{ }, @{ $service->{languages} // [] } ),
+ $service->{time_zone} // q{},
);
}
exit 0;
}
+$service //= 'VRN';
+
parse_mot_options();
my ( $from_stop, @via_stops ) = @ARGV;
@@ -164,13 +176,15 @@ sub parse_mot_options {
for my $type ( split( qr{,}, $types ) ) {
if ( $type eq 'help' or $type eq 'list' or $type eq q{?} ) {
- $service //= 'DB';
+ $service //= 'VRN';
my $desc = Travel::Routing::DE::HAFAS::get_service($service);
if ($desc) {
my @mots = @{ $desc->{productbits} };
for my $mot ( @{ $desc->{productbits} } ) {
if ( ref($mot) eq 'ARRAY' ) {
- printf( "%-10s %s\n", @{$mot} );
+ if ( $mot->[0] ne '_' ) {
+ printf( "%-10s %s\n", @{$mot} );
+ }
}
else {
say $mot;
@@ -273,7 +287,12 @@ sub format_delay {
sub show_message {
my ($msg) = @_;
- if ( $verbosity >= ( $min_verbosity{ $msg->type } // 0 ) ) {
+ if (
+ $msg->text
+ and ( not $msg->type
+ or $verbosity >= ( $min_verbosity{ $msg->type } // 0 ) )
+ )
+ {
if ( $msg->short ) {
printf( "| %s\n", $msg->short );
}
@@ -284,11 +303,21 @@ sub show_message {
}
if ( my $err = $hafas->errstr ) {
- say STDERR "Request error: ${err}";
- if ( $hafas->errcode
- and ( $hafas->errcode eq 'H730' or $hafas->errcode eq 'LOCATION' ) )
- {
- show_similar_stops();
+ say STDERR "Backend error: ${err}";
+ if ( $hafas->errcode ) {
+ if ( $hafas->errcode eq 'H730' or $hafas->errcode eq 'LOCATION' ) {
+ show_similar_stops();
+ }
+ elsif ( $hafas->errcode eq 'H890' ) {
+ say q{};
+ say 'HAFAS was unable to find suitable connections.';
+ say
+'Maybe your mode of transport (-m) or change (-c / -C) filters are too restrictive?';
+ }
+ elsif ( $hafas->errcode eq 'H9380' ) {
+ say q{};
+ say 'Arrival / departure / intermediate stops must not overlap.';
+ }
}
exit 2;
}
@@ -451,9 +480,13 @@ for my $res ( $hafas->connections ) {
printf("\n???\n");
}
for my $msg ( $sec->messages ) {
- if ( $msg->code eq 'text.connection.section.arrival.date.deviation'
- or $msg->code eq
- 'text.connection.section.departure.date.deviation' )
+ if (
+ $msg->code
+ and ( $msg->code eq
+ 'text.connection.section.arrival.date.deviation'
+ or $msg->code eq
+ 'text.connection.section.departure.date.deviation' )
+ )
{
next;
}
@@ -468,7 +501,7 @@ __END__
=head1 NAME
-hafas - Interface to HAFAS (e.g. Deutsche Bahn) itinerary services
+hafas - Interface to HAFAS-based itinerary services
=head1 SYNOPSIS
@@ -477,13 +510,12 @@ B<hafas> [B<-d> I<date>] [B<-t> I<time>] [B<-m> I<motlist>]
=head1 VERSION
-version 0.06
+version 0.10
=head1 DESCRIPTION
B<hafas> is a command line client for HAFAS-based public transit itinerary
-services, e.g. the one operated by Deutsche Bahn. It requests connections
-between two stops and prints the results.
+services. It requests connections between two stops and prints the results.
=head1 OPTIONS
@@ -528,6 +560,10 @@ Note that requesting an invalid/unsupported language may lead to garbage output.
List known HAFAS installations and exit. Use B<-s>|B<--service> to select an
operator from this list for a HAFAS request.
+Instances marked with an exclamation mark (C<< ! >>) are behind a GeoIP filter
+and may need a proxy to work. See the documentation of get_active_service in
+Travel::Status::DE::HAFAS(3pm) for details.
+
=item B<-m>, B<--mot> I<motlist>
By default, B<hafas> considers all modes of transport for routing. With
@@ -542,8 +578,8 @@ The I<mot> types depend on the used service. Use C<< -m help >> to list them.
=item B<-s>, B<--service> I<service>
-Use the API provided by I<service> for routing; defaults to DB (Deutsche Bahn).
-See B<--list> for a list of known services.
+Use the API provided by I<service> for routing; defaults to VRN
+(Verkehrsverbund Rhein-Neckar). See B<--list> for a list of known services.
=item B<-t>, B<--time>, B<--depart> I<hh>:I<mm>
@@ -597,7 +633,7 @@ None.
=head1 BUGS AND LIMITATIONS
-The non-default services (anything other than DB) are not well-tested.
+Some services are not well-tested.
=head1 AUTHOR