From 9cb71f78d09b8dc6e7b431c31c2cfac7657d7682 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Tue, 24 Dec 2024 10:01:08 +0100 Subject: add journey support --- bin/dbris-m | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'bin/dbris-m') diff --git a/bin/dbris-m b/bin/dbris-m index cc495a8..3e3488b 100755 --- a/bin/dbris-m +++ b/bin/dbris-m @@ -74,7 +74,7 @@ elsif ( $opt{station} =~ m{ ^ [?] (? .*) $ }x ) { delete $opt{station}; } elsif ( $opt{station} =~ m{[|]} ) { - $opt{journey} = { id => $opt{station} }; + $opt{journey} = $opt{station}; delete $opt{station}; } elsif ( $opt{station} !~ m{ ^ \d+ $ }x ) { @@ -191,6 +191,44 @@ if ( $opt{station} ) { } } } +elsif ( $opt{journey} ) { + my $trip = $status->result; + + my $max_name = max map { length( $_->name ) } $trip->route; + my $max_platform = max map { length( $_->platform // q{} ) } $trip->route; + + say $trip->train; + say q{}; + + for my $stop ( $trip->route ) { + if ( $stop->is_cancelled ) { + print(' --:-- '); + } + elsif ( $stop->arr and $stop->dep ) { + printf( '%s → %s', + $stop->arr->strftime('%H:%M'), + $stop->dep->strftime('%H:%M'), + ); + } + elsif ( $stop->dep ) { + printf( ' %s', $stop->dep->strftime('%H:%M') ); + } + elsif ( $stop->arr ) { + printf( '%s ', $stop->arr->strftime('%H:%M') ); + } + else { + print(' '); + } + printf( " %${max_name}s %${max_platform}s\n", + $stop->name, $stop->platform // q{} ); + } + if ( $trip->messages ) { + say q{}; + } + for my $message ( $trip->messages ) { + say $message->{text}; + } +} elsif ( $opt{geoSearch} ) { for my $result ( $status->results ) { if ( defined $result->eva ) { -- cgit v1.2.3