From ab020b55629130202638ee2019117718a854a5ff Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 3 Dec 2011 14:04:52 +0100 Subject: Add language switch for extra information (delay reasons etc.) --- Changelog | 4 ++++ bin/db-ris | 18 +++++++++++++----- lib/Travel/Status/DE/DeutscheBahn.pm | 18 ++++++++++++++---- lib/Travel/Status/DE/DeutscheBahn/Result.pm | 3 ++- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Changelog b/Changelog index 60619cf..cfd1e70 100644 --- a/Changelog +++ b/Changelog @@ -1,8 +1,12 @@ git HEAD * Detect ambiguous input errors (available via errstr) + * Add language switch for additional information (german/english) * Result: Add line (== train) and date accessors + [db-ris] + * Add -l / --lang option + Travel::Status::DE::DeutscheBahn 1.00 - Sun Sep 04 2011 [db-ris] diff --git a/bin/db-ris b/bin/db-ris index 082505f..3c58b22 100755 --- a/bin/db-ris +++ b/bin/db-ris @@ -16,6 +16,7 @@ my $filter_via; my $ignore_late = 0; my $show_full_route = 0; my $types = q{}; +my $language; my @output; @@ -25,6 +26,7 @@ GetOptions( 'd|date=s' => \$date, 'f|full-route' => \$show_full_route, 'h|help' => sub { show_help(0) }, + 'l|lang=s' => \$language, 'L|ignore-late' => \$ignore_late, 'm|mot=s' => \$types, 't|time=s' => \$time, @@ -43,10 +45,11 @@ for my $type ( split( qr{,}, $types ) ) { } my $status = Travel::Status::DE::DeutscheBahn->new( - date => $date, - mot => \%train_type, - station => shift || show_help(1), - time => $time, + date => $date, + language => $language, + mot => \%train_type, + station => shift || show_help(1), + time => $time, ); sub show_help { @@ -164,6 +167,11 @@ Date to list departures for. Default: today. Display complete routes (including arrival times) of all trains. +=item B<-l>, B<--lang> B|B|B|B + +Set language used for additional information. Supports Beutsch (default), +Bnglish, Btalian and dutch (B). + =item B<-L>, B<--ignore-late> Do not display delayed trains. @@ -185,7 +193,7 @@ argements: You can prefix an argument with "!" to hide it. The default is C<< ice,ic_ec,d,nv,s >>. Note that B<-m> does not replace the default, so if you -only want to see S-Bahn und U-Bahn departures, you'd have to use C<< -m +only want to see S-Bahn and U-Bahn departures, you'd have to use C<< -m !ice,!ic_ec,!d,!nv,u >>. =item B<-t>, B<--time> I:I diff --git a/lib/Travel/Status/DE/DeutscheBahn.pm b/lib/Travel/Status/DE/DeutscheBahn.pm index 018eaa9..780d05d 100644 --- a/lib/Travel/Status/DE/DeutscheBahn.pm +++ b/lib/Travel/Status/DE/DeutscheBahn.pm @@ -21,6 +21,8 @@ sub new { my $reply; + my $lang = $conf{language} // 'd'; + if ( not $conf{station} ) { confess('You need to specify a station'); } @@ -45,7 +47,8 @@ sub new { REQTrain_name => q{}, start => 'yes', boardType => $conf{mode} // 'dep', -# L => 'vs_java3', + + # L => 'vs_java3', }, }; @@ -57,7 +60,9 @@ sub new { bless( $ref, $obj ); - $reply = $ua->post( 'http://reiseauskunft.bahn.de/bin/bhftafel.exe/dn?rt=1', + $reply + = $ua->post( + "http://reiseauskunft.bahn.de/bin/bhftafel.exe/${lang}n?rt=1", $ref->{post} ); if ( $reply->is_error ) { @@ -191,7 +196,7 @@ sub results { my $first = 1; my ( $time, $train, $route, $dest, $platform, $info ) = map { get_node( $tr, @{$_} ) } @parts; - my $e_train_more = ($tr->findnodes($xp_train_more))[0]; + my $e_train_more = ( $tr->findnodes($xp_train_more) )[0]; if ( not( $time and $dest ) ) { next; @@ -201,7 +206,7 @@ sub results { my $date = $+{date}; - substr($date, 6, 0) = '20'; + substr( $date, 6, 0 ) = '20'; $platform //= q{}; $info //= q{}; @@ -311,6 +316,11 @@ The train station to report for, e.g. "Essen HBf". Mandatory. Date to report for. Defaults to the current day. +=item B => I + +Set language for additional information. Accepted arguments: Beutsch, +Bnglish, Btalian, B (dutch). + =item B