From 915bad108d838716c17ac605d13d59624b2bc539 Mon Sep 17 00:00:00 2001 From: Derf Null Date: Fri, 7 Apr 2023 14:49:32 +0200 Subject: add geoSearch mode --- bin/hafas-m | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'bin/hafas-m') diff --git a/bin/hafas-m b/bin/hafas-m index 2b6c2d0..53f232b 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -59,7 +59,14 @@ my %opt = ( service => $service, ); -if ( $opt{station} =~ m{[|]} ) { +if ( $opt{station} =~ m{ ^ (? [0-9.]+ ) : (? [0-9].+ ) $ }x ) { + $opt{geoSearch} = { + lat => $+{lat}, + lon => $+{lon}, + }; + delete $opt{station}; +} +elsif ( $opt{station} =~ m{[|]} ) { $opt{journey} = { id => $opt{station} }; delete $opt{station}; } @@ -234,7 +241,17 @@ if ( my $err = $status->errstr ) { exit 2; } -if ( $opt{journey} ) { +if ( $opt{geoSearch} ) { + for my $result ( $status->results ) { + printf( + "%5.1f km %8d %s\n", + $result->{distance_m} * 1e-3, + $result->{eva}, $result->{name} + ); + } + exit 0; +} +elsif ( $opt{journey} ) { my $result = $status->result; printf( "%s → %s", $result->name, $result->route_end ); -- cgit v1.2.3