From 3c0333278581fec8998ebe485c70778084c20b5a Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 19 Nov 2023 16:52:36 +0100 Subject: Implement journeyMatch requests --- bin/hafas-m | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'bin/hafas-m') diff --git a/bin/hafas-m b/bin/hafas-m index fb1f71b..6484387 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -84,6 +84,10 @@ elsif ( $opt{station} =~ m{[|]} ) { $opt{journey} = { id => $opt{station} }; delete $opt{station}; } +elsif ( $opt{station} =~ m{ ^ [!] (? .*) $ }x ) { + $opt{journeyMatch} = $+{query}; + delete $opt{station}; +} if ( $date or $time ) { my $dt = DateTime->now( time_zone => 'Europe/Berlin' ); @@ -337,6 +341,28 @@ 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 ) { @@ -399,7 +425,7 @@ B [B<-d> I] [B<-t> I