From 98ddd776a6ab59756fbb07a1f48c7b2431d5c0fe Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Tue, 21 Nov 2023 17:59:40 +0100 Subject: trip search: show journey details if the query is unique --- bin/hafas-m | 58 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 24 deletions(-) (limited to 'bin') diff --git a/bin/hafas-m b/bin/hafas-m index 6484387..ac076f6 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -288,6 +288,37 @@ if ($json_output) { exit 0; } +if ( $opt{journeyMatch} ) { + if ( scalar $status->results == 1 ) { + my ($journey) = $status->results; + $opt{journey} = { id => $journey->id }; + delete $opt{journeyMatch}; + $status = Travel::Status::DE::HAFAS->new(%opt); + } + else { + for my $result ( $status->results ) { + my $start = ( $result->route )[0]; + my $end = ( $result->route )[-1]; + say $result->id; + print $result->name; + if ( $result->number ) { + printf( " | Zug %s", $result->number ); + } + if ( $result->line_no ) { + printf( " | Linie %s", $result->line_no ); + } + say q{}; + printf( "%s ab %s\n", + $start->dep->strftime('%H:%M'), + $start->loc->name ); + printf( "%s an %s\n\n", + $end->arr->strftime('%H:%M'), + $end->loc->name ); + } + exit 0; + } +} + if ( $opt{geoSearch} ) { for my $result ( $status->results ) { printf( @@ -341,28 +372,6 @@ elsif ( $opt{journey} ) { } exit 0; } -elsif ( $opt{journeyMatch} ) { - for my $result ( $status->results ) { - my $start = ( $result->route )[0]; - my $end = ( $result->route )[-1]; - say $result->id; - print $result->name; - if ( $result->number ) { - printf( " | Zug %s", $result->number ); - } - if ( $result->line_no ) { - printf( " | Linie %s", $result->line_no ); - } - say q{}; - printf( "%s ab %s\n", - $start->dep->strftime('%H:%M'), - $start->loc->name ); - printf( "%s an %s\n\n", - $end->arr->strftime('%H:%M'), - $end->loc->name ); - } - exit 0; -} my $message_id = 1; for my $m ( $status->messages ) { @@ -471,8 +480,9 @@ IB<:>I geocoordinates with EVA ID and name. =head2 Trip Search (BI) -List journey IDs that match the train numer I (e.g. "ICE 205" or -"S 31111"). +Show trip details (see below) for the train number provided in I +(e.g. "ICE 205" or "S 31111") if it resolves into a single journey ID. +Otherwise, list all journey IDs that match I. =head2 Trip Details (I) -- cgit v1.2.3