diff options
-rwxr-xr-x | bin/hafas-m | 4 | ||||
-rw-r--r-- | lib/Travel/Status/DE/HAFAS.pm | 37 |
2 files changed, 30 insertions, 11 deletions
diff --git a/bin/hafas-m b/bin/hafas-m index 5dea42e..f279b04 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -18,6 +18,7 @@ my $types = q{}; my $language; my $developer_mode; my ( $list_services, $service, $hafas_url ); +my @excluded_mots; my @output; @@ -50,6 +51,7 @@ if ($list_services) { for my $type ( split( qr{,}, $types ) ) { if ( substr( $type, 0, 1 ) eq q{!} ) { $train_type{ substr( $type, 1 ) } = 0; + push( @excluded_mots, substr( $type, 1 ) ); } else { $train_type{$type} = 1; @@ -59,7 +61,7 @@ for my $type ( split( qr{,}, $types ) ) { my $status = Travel::Status::DE::HAFAS->new( date => $date, language => $language, - mot => \%train_type, + excluded_mots => \@excluded_mots, station => shift || show_help(1), time => $time, mode => $arrivals ? 'arr' : 'dep', diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 7cd1c97..b47c2fe 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -16,18 +16,19 @@ our $VERSION = '1.05'; my %hafas_instance = ( BVG => { - url => 'http://bvg.hafas.de/bin/stboard.exe', - name => 'Berliner Verkehrsgesellschaft', + url => 'http://bvg.hafas.de/bin/stboard.exe', + name => 'Berliner Verkehrsgesellschaft', productbits => [qw[s u tram bus ferry ice regio ondemand]], }, DB => { - url => 'http://reiseauskunft.bahn.de/bin/bhftafel.exe', - name => 'Deutsche Bahn', - productbits => [qw[ice ic_ec d regio s bus ferry u tram ondemand x x x x]], + url => 'http://reiseauskunft.bahn.de/bin/bhftafel.exe', + name => 'Deutsche Bahn', + productbits => + [qw[ice ic_ec d regio s bus ferry u tram ondemand x x x x]], }, NASA => { - url => 'http://reiseauskunft.insa.de/bin/stboard.exe', - name => 'Nahverkehrsservice Sachsen-Anhalt', + url => 'http://reiseauskunft.insa.de/bin/stboard.exe', + name => 'Nahverkehrsservice Sachsen-Anhalt', productbits => [qw[ice ice regio regio regio tram bus ondemand]], }, ); @@ -60,6 +61,7 @@ sub new { my $ref = { active_service => $service, developer_mode => $conf{developer_mode}, + excluded_mots => $conf{excluded_mots}, post => { input => $conf{station}, date => $date, @@ -114,10 +116,25 @@ sub set_productfilter { my $service = $self->{active_service}; - if ($service and exists $hafas_instance{$service}{productbits}) { - $self->{post}{productsFilter} - = '1' x ( scalar @{ $hafas_instance{$service}{productbits} } ); + if ( not $service or not exists $hafas_instance{$service}{productbits} ) { + return; } + + $self->{post}{productsFilter} + = '1' x ( scalar @{ $hafas_instance{$service}{productbits} } ); + + if ( $self->{excluded_mots} and @{ $self->{excluded_mots} } ) { + my %mot_pos; + for my $i ( 0 .. $#{ $hafas_instance{$service}{productbits} } ) { + $mot_pos{ $hafas_instance{$service}{productbits}[$i] } = $i; + } + for my $mot ( @{ $self->{excluded_mots} } ) { + if ( exists $mot_pos{$mot} ) { + substr( $self->{post}{productsFilter}, $mot_pos{$mot}, 1 ) = 0; + } + } + } + } sub check_input_error { |