summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/hafas-m42
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm11
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{ ^ (?<lat> [0-9.]+ ) : (?<lon> [0-9].+ ) $ }x ) {
@@ -369,11 +375,11 @@ hafas-m - Interface to the DeutscheBahn/HAFAS online departure monitor
=head1 SYNOPSIS
B<hafas-m> [B<-d> I<date>] [B<-t> I<time>] [B<-m> I<motlist>]
-[B<-s> I<service>] I<station>
+[B<-s> I<service>] [B<-l> I<language>] I<station>
B<hafas-m> [B<-s> I<service>] B<?>I<query>|I<lat>B<:>I<lon>
-B<hafas-m> [B<-s> I<service>] I<journeyID>
+B<hafas-m> [B<-s> I<service>] [B<-l> I<language>] I<journeyID>
=head1 VERSION
@@ -442,6 +448,12 @@ Print result(s) as JSON. This is a dump of internal data structures and not
guaranteed to remain stable between minor versions. Please use the
Travel::Status::DE::HAFAS(3pm) module if you need a proper API.
+=item B<-l>, B<--language> I<language>
+
+Request free-text messages to be provided in I<language>.
+See B<--list> for a list of languages supported by individual HAFAS instances.
+Note that requesting an invalid/unsupported language may lead to garbage output.
+
=item B<--list>
List known HAFAS installations and exit. Use B<-s>|B<--service> to select an
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index 780d89f..cd9e9f2 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -33,6 +33,7 @@ my %hafas_instance = (
name => 'Deutsche Bahn',
productbits => [qw[ice ic_ec d regio s bus ferry u tram ondemand]],
salt => 'bdI8UVj4' . '0K5fvxwf',
+ languages => [qw[de en fr es]],
request => {
client => {
id => 'DB',
@@ -339,6 +340,10 @@ sub new {
};
}
+ if ( $conf{language} ) {
+ $req->{lang} = $conf{language};
+ }
+
$self->{strptime_obj} //= DateTime::Format::Strptime->new(
pattern => '%Y%m%dT%H%M%S',
time_zone => 'Europe/Berlin',
@@ -986,6 +991,12 @@ If this option is set, only the modes of transport appearing in I<mot1>,
I<mot2>, ... will be returned. The supported modes depend on B<service>, use
B<get_services> or B<get_service> to get the supported values.
+=item B<language> => I<language>
+
+Request text messages to be provided in I<language>. Supported languages depend
+on B<service>, use B<get_services> or B<get_service> to get the supported
+values. Providing an unsupported or invalid value may lead to garbage output.
+
=item B<lookahead> => I<int> (station)
Request arrivals/departures that occur up to I<int> minutes after the specified datetime.