From aafcd2dd8ef4efa238ce1d0df2b829b098a303c4 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 16 Oct 2022 13:47:42 +0200 Subject: parse arr/dep times in journey route --- bin/hafas-m | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'bin') 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 ) { -- cgit v1.2.3