diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/hafas-m (renamed from bin/db-ris) | 104 |
1 files changed, 44 insertions, 60 deletions
@@ -7,17 +7,16 @@ our $VERSION = '1.05'; use Getopt::Long qw(:config no_ignore_case); use List::Util qw(first max); -use Travel::Status::DE::DeutscheBahn; +use Travel::Status::DE::HAFAS; my %train_type; my ( $date, $time ); -my $arrivals = 0; -my $filter_via; -my $ignore_late = 0; -my $show_full_route = 0; -my $types = q{}; +my $arrivals = 0; +my $ignore_late = 0; +my $types = q{}; my $language; +my $developer_mode; my @output; @@ -26,14 +25,13 @@ binmode( STDOUT, ':encoding(utf-8)' ); GetOptions( 'a|arrivals' => \$arrivals, 'd|date=s' => \$date, - 'f|full-route' => \$show_full_route, 'h|help' => sub { show_help(0) }, 'l|lang=s' => \$language, 'L|ignore-late' => \$ignore_late, 'm|mot=s' => \$types, 't|time=s' => \$time, - 'v|via=s' => \$filter_via, 'V|version' => \&show_version, + 'devmode' => \$developer_mode, ) or show_help(1); @@ -46,27 +44,28 @@ for my $type ( split( qr{,}, $types ) ) { } } -my $status = Travel::Status::DE::DeutscheBahn->new( - date => $date, - language => $language, - mot => \%train_type, - station => shift || show_help(1), - time => $time, - mode => $arrivals ? 'arr' : 'dep', +my $status = Travel::Status::DE::HAFAS->new( + date => $date, + language => $language, + mot => \%train_type, + station => shift || show_help(1), + time => $time, + mode => $arrivals ? 'arr' : 'dep', + developer_mode => $developer_mode, ); sub show_help { my ($code) = @_; - print 'Usage: db-ris [-d <dd.mm.yyyy>] [-m <motlist>] [-t <time>] ' - . "[-v <via>] <station>\n" - . "See also: man db-ris\n"; + print 'Usage: hafas-m [-d <dd.mm.yyyy>] [-m <motlist>] [-t <time>] ' + . "<station>\n" + . "See also: man hafas-m\n"; exit $code; } sub show_version { - say "db-ris version ${VERSION}"; + say "hafas-m version ${VERSION}"; exit 0; } @@ -80,23 +79,28 @@ sub display_result { die("Nothing to show\n"); } - for my $i ( 0 .. 5 ) { + for my $i ( 0 .. 4 ) { $line_length[$i] = max map { length( $_->[$i] ) } @lines; } for my $line (@lines) { - printf( - join( q{ }, ( map { "%-${_}s" } @line_length ) ) . "\n", - @{$line}[ 0 .. 5 ] - ); - if ( $line->[7] ) { - print " " . $line->[7] . "\n"; + my $d = $line->[6]; + if ( $d->messages ) { + print "\n"; + for my $msg ( $d->messages ) { + printf( "# %s\n", $msg ); + } } - if ($show_full_route) { - print "\n" . $line->[6] . "\n\n\n"; + printf( + join( q{ }, ( map { "%-${_}s" } @line_length ) ), + @{$line}[ 0 .. 4 ] + ); + if ( $line->[5] ) { + print $line->[5]; } + print "\n"; } return; @@ -109,14 +113,6 @@ if ( my $err = $status->errstr ) { for my $d ( $status->results() ) { - my @via; - - @via = $d->route; - - if ( $filter_via and not( first { $_ =~ m{$filter_via}io } @via ) ) { - next; - } - if ( $ignore_late and $d->delay ) { next; } @@ -125,14 +121,14 @@ for my $d ( $status->results() ) { @output, [ $d->time, + $d->is_cancelled + ? 'CANCELED' + : ( $d->delay ? '+' . $d->delay : q{} ), $d->train, - $arrivals ? q{} : join( q{ }, $d->route_interesting ), $d->route_end, - $d->platform, + ( $d->platform // q{} ) . ( $d->is_changed_platform ? ' !' : q{} ), $d->info, - join( "\n", - map { sprintf( '%-5s %s', @{$_} ) } $d->route_timetable ), - $d->route_info, + $d ] ); } @@ -143,12 +139,12 @@ __END__ =head1 NAME -db-ris - Interface to the DeutscheBahn online departure monitor +hafas-m - Interface to the DeutscheBahn/HAFAS online departure monitor =head1 SYNOPSIS -B<db-ris> [B<-a>] [B<-d> I<date>] [B<-L>] [B<-m> I<motlist>] [B<-t> I<time>] -[B<-v> I<via>] I<station> +B<hafas-m> [B<-a>] [B<-d> I<date>] [B<-L>] [B<-m> I<motlist>] [B<-t> I<time>] +I<station> =head1 VERSION @@ -156,8 +152,8 @@ version 1.05 =head1 DESCRIPTION -db-ris is an interface to the DeutscheBahn departure monitor -available at L<http://reiseauskunft.bahn.de/bin/bhftafel.exe/dn>. +hafas-m is an interface to HAFAS-based departure monitors, for instance the +one available at L<http://reiseauskunft.bahn.de/bin/bhftafel.exe/dn>. It requests all departures at I<station> (optionally filtered by date, time, route and means of transport) and lists them on stdout, similar to the big @@ -178,10 +174,6 @@ I<station>, not I<station> and end. Date to list departures for. Default: today. -=item B<-f>, B<--full-route> - -Display complete routes (including arrival times) of all trains. - =item B<-l>, B<--lang> B<d>|B<e>|B<i>|B<n> Set language used for additional information. Supports B<d>eutsch (default), @@ -215,13 +207,6 @@ only want to see S-Bahn and U-Bahn departures, you'd have to use C<< -m Time to list departures for. Default: now. -=item B<-v>, B<--via> I<regex> - -Only display trains whose route (all stations between the current stop and the -destination) matches the perl regular expression I<regex>. The match is not -case-sensitive. Use '^regex$' to match a full string, but be aware that this -may not work as expected. - =item B<-V>, B<--version> Show version information. @@ -250,12 +235,11 @@ None. =head1 BUGS AND LIMITATIONS -There are a few character encoding problems (most notably, B<--via> does not -understand UTF-8 umlauts). +Unknown. =head1 AUTHOR -Copyright (C) 2011 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt> +Copyright (C) 2015 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE |