summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/hafas-m6
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm20
2 files changed, 18 insertions, 8 deletions
diff --git a/bin/hafas-m b/bin/hafas-m
index ee3ae78..5f49a19 100755
--- a/bin/hafas-m
+++ b/bin/hafas-m
@@ -17,7 +17,7 @@ my $ignore_late = 0;
my $types = q{};
my $language;
my $developer_mode;
-my $list_services;
+my ( $list_services, $service, $hafas_url );
my @output;
@@ -30,7 +30,9 @@ GetOptions(
'l|lang=s' => \$language,
'L|ignore-late' => \$ignore_late,
'm|mot=s' => \$types,
+ 's|service=s' => \$service,
't|time=s' => \$time,
+ 'u|url=s' => \$hafas_url,
'V|version' => \&show_version,
'devmode' => \$developer_mode,
'list' => \$list_services,
@@ -62,6 +64,8 @@ my $status = Travel::Status::DE::HAFAS->new(
time => $time,
mode => $arrivals ? 'arr' : 'dep',
developer_mode => $developer_mode,
+ service => $service,
+ url => $hafas_url,
);
sub show_help {
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index fe8cf2e..6589359 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -27,9 +27,9 @@ sub new {
my $date = $conf{date} // strftime( '%d.%m.%Y', localtime(time) );
my $time = $conf{time} // strftime( '%H:%M', localtime(time) );
- my $lang = $conf{language} // 'd';
- my $mode = $conf{mode} // 'dep';
- my $service = $conf{service} // 'DB';
+ my $lang = $conf{language} // 'd';
+ my $mode = $conf{mode} // 'dep';
+ my $service = $conf{service};
my %lwp_options = %{ $conf{lwp_options} // { timeout => 10 } };
@@ -43,6 +43,10 @@ sub new {
confess('You need to specify a station');
}
+ if ( not defined $service and not defined $conf{url} ) {
+ $service = 'DB';
+ }
+
my $ref = {
active_service => $service,
developer_mode => $conf{developer_mode},
@@ -60,7 +64,7 @@ sub new {
$ref->set_productfilter;
- my $url = $hafas_instance{$service}{url} . '/' . $lang . 'n';
+ my $url = ( $conf{url} // $hafas_instance{$service}{url} ) . "/${lang}n";
$reply = $ua->post( $url, $ref->{post} );
@@ -100,8 +104,10 @@ sub set_productfilter {
my $service = $self->{active_service};
- $self->{post}{productsFilter}
- = '1' x ( scalar @{ $hafas_instance{$service}{productbits} } );
+ if ($service) {
+ $self->{post}{productsFilter}
+ = '1' x ( scalar @{ $hafas_instance{$service}{productbits} } );
+ }
}
sub check_input_error {
@@ -207,7 +213,7 @@ sub get_services {
sub get_service {
my ($self) = @_;
- return %{ $hafas_instance{ $self->active_service } };
+ return %{ $hafas_instance{ $self->{active_service} } };
}
1;