diff options
author | Birte Kristina Friesel <birte.friesel@uos.de> | 2023-11-21 17:59:40 +0100 |
---|---|---|
committer | Birte Kristina Friesel <birte.friesel@uos.de> | 2023-11-21 17:59:40 +0100 |
commit | 98ddd776a6ab59756fbb07a1f48c7b2431d5c0fe (patch) | |
tree | a88190c3caff639181c6b5a0793681e9c17f996f /bin/hafas-m | |
parent | 05c60f407f72cc339f55dade0aa67a87792f58d6 (diff) |
trip search: show journey details if the query is unique
Diffstat (limited to 'bin/hafas-m')
-rwxr-xr-x | bin/hafas-m | 58 |
1 files changed, 34 insertions, 24 deletions
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 @@ I<lat>B<:>I<lon> geocoordinates with EVA ID and name. =head2 Trip Search (B<!>I<query>) -List journey IDs that match the train numer I<query> (e.g. "ICE 205" or -"S 31111"). +Show trip details (see below) for the train number provided in I<query> +(e.g. "ICE 205" or "S 31111") if it resolves into a single journey ID. +Otherwise, list all journey IDs that match I<query>. =head2 Trip Details (I<journeyID>) |