From a60779e8b19a1db11a65467163e6be1ccfd8005b Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 29 Oct 2023 14:09:50 +0100 Subject: allow users to specify the request language --- bin/hafas-m | 42 +++++++++++++++++++++++++++--------------- lib/Travel/Status/DE/HAFAS.pm | 11 +++++++++++ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/bin/hafas-m b/bin/hafas-m index 7a683b7..ceac8cc 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -14,7 +14,7 @@ use List::MoreUtils qw(uniq); use List::Util qw(first max); use Travel::Status::DE::HAFAS; -my ( $date, $time ); +my ( $date, $time, $language ); my $arrivals = 0; my $types = q{}; my $developer_mode; @@ -30,23 +30,28 @@ for my $arg (@ARGV) { } GetOptions( - 'a|arrivals' => \$arrivals, - 'd|date=s' => \$date, - 'h|help' => sub { show_help(0) }, - 'm|mot=s' => \$types, - 's|service=s' => \$service, - 't|time=s' => \$time, - 'V|version' => \&show_version, - 'devmode' => \$developer_mode, - 'json' => \$json_output, - 'list' => \$list_services, + 'a|arrivals' => \$arrivals, + 'd|date=s' => \$date, + 'h|help' => sub { show_help(0) }, + 'l|language=s' => \$language, + 'm|mot=s' => \$types, + 's|service=s' => \$service, + 't|time=s' => \$time, + 'V|version' => \&show_version, + 'devmode' => \$developer_mode, + 'json' => \$json_output, + 'list' => \$list_services, ) or show_help(1); if ($list_services) { - printf( "%-40s %-14s\n\n", 'operator', 'abbr. (-s)' ); + printf( "%-40s %-14s %s\n\n", 'operator', 'abbr. (-s)', 'languages (-l)' ); for my $service ( Travel::Status::DE::HAFAS::get_services() ) { - printf( "%-40s %-14s\n", @{$service}{qw(name shortname)} ); + printf( + "%-40s %-14s %s\n", + @{$service}{qw(name shortname)}, + join( q{ }, @{ $service->{languages} // [] } ) + ); } exit 0; } @@ -60,6 +65,7 @@ my %opt = ( arrivals => $arrivals, developer_mode => $developer_mode, service => $service, + language => $language, ); if ( $opt{station} =~ m{ ^ (? [0-9.]+ ) : (? [0-9].+ ) $ }x ) { @@ -369,11 +375,11 @@ hafas-m - Interface to the DeutscheBahn/HAFAS online departure monitor =head1 SYNOPSIS B [B<-d> I] [B<-t> I