diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-10-16 13:47:42 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-10-16 13:47:42 +0200 |
commit | aafcd2dd8ef4efa238ce1d0df2b829b098a303c4 (patch) | |
tree | 09c536340abc2d31b39ef2a36146628eeecbe897 /bin/hafas-m | |
parent | 85b59dfcba8ddd2f1e0ab312b15ca66443902d9c (diff) |
parse arr/dep times in journey route
Diffstat (limited to 'bin/hafas-m')
-rwxr-xr-x | bin/hafas-m | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/bin/hafas-m b/bin/hafas-m index a33c5dc..dfb5d71 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -5,6 +5,7 @@ use 5.014; our $VERSION = '3.01'; +use utf8; use DateTime; use Encode qw(decode); use Getopt::Long qw(:config no_ignore_case); @@ -60,6 +61,11 @@ my %opt = ( url => $hafas_url, ); +if ( $opt{station} =~ m{[|]} ) { + $opt{journey} = { id => $opt{station} }; + delete $opt{station}; +} + if ( $date or $time ) { my $dt = DateTime->now( time_zone => 'Europe/Berlin' ); if ($date) { @@ -216,6 +222,32 @@ if ( my $err = $status->errstr ) { exit 2; } +if ( $opt{journey} ) { + my $result = $status->result; + + printf( "%s → %s\n", $result->line, $result->destination ); + + for my $stop ( $result->route ) { + printf( + "%5s %s %5s %5s %s\n", + $stop->{arr} ? $stop->{arr}->strftime('%H:%M') : q{}, + ( $stop->{arr} and $stop->{dep} ) ? '→' : q{ }, + $stop->{dep} ? $stop->{dep}->strftime('%H:%M') : q{}, + $stop->{delay} ? sprintf( '(%+d)', $stop->{delay} ) : q{}, + $stop->{name} + ); + } + + for my $msg ( $result->messages ) { + say ''; + if ( $msg->short ) { + printf( "%s\n", $msg->short ); + } + printf( "%s\n", $msg->text ); + } + exit 0; +} + my $message_id = 1; for my $m ( $status->messages ) { if ( $m->ref_count > 1 ) { |