Commit 86c3e352 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add support for means of transport filtering

parent c1edc66f
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -9,14 +9,29 @@ use Getopt::Long;
use Travel::Status::DE::DeutscheBahn;

my ( $date, $time );
my $types = q{};
my %train_type;

binmode( STDOUT, ':encoding(utf-8)' );

GetOptions(
	'd|date=s' => \$date,
	'm|mot=s'  => \$types,
	't|time=s' => \$time,
);

for my $type ( split( qr{,}, $types ) ) {
	if ( substr( $type, 0, 1 ) eq q{!} ) {
		$train_type{ substr( $type, 1 ) } = 0;
	}
	else {
		$train_type{$type} = 1;
	}
}

my $status = Travel::Status::DE::DeutscheBahn->new(
	date    => $date,
	mot     => \%train_type,
	station => shift,
	time    => $time,
);
@@ -58,7 +73,7 @@ for my $d ( $status->departures() ) {
	}

	printf(
		"%5s %-10s %-80s %-20s %-2d %s\n",
		"%5s %-10s %-80s %-20s %-2s %s\n",
		$d->time, $d->train, join( q{  }, @via_show ),
		$d->destination, $d->platform, $d->info
	);
+36 −11
Original line number Diff line number Diff line
@@ -24,21 +24,34 @@ sub new {
	}

	my $ref = {
		mot_filter => [
			$conf{mot}->{ice}   // 1,
			$conf{mot}->{ic_ec} // 1,
			$conf{mot}->{d}     // 1,
			$conf{mot}->{nv}    // 1,
			$conf{mot}->{s}     // 1,
			$conf{mot}->{bus}   // 0,
			$conf{mot}->{ferry} // 0,
			$conf{mot}->{u}     // 0,
			$conf{mot}->{tram}  // 0,
		],
		post => {
			advancedProductMode => q{},
			input               => $conf{station},
			inputRef       => q{#},
			date                => $conf{date} || $date,
			time                => $conf{time} || $time,
			productsFilter => '1111101000000000',
			REQTrain_name       => q{},
			maxJourneys    => 20,
			delayedJourney => undef,
			start               => 'Suchen',
			boardType      => 'Abfahrt',
			ao             => 'yes',
			boardType           => 'dep',
		},
	};

	for my $i ( 0 .. @{ $ref->{mot_filter} } ) {
		if ( $ref->{mot_filter}->[$i] ) {
			$ref->{post}->{"GUIREQProduct_$i"} = 'on';
		}
	}

	$ref->{html}
	  = $ua->post( 'http://reiseauskunft.bahn.de/bin/bhftafel.exe/dn?rt=1',
		$ref->{post} )->content();
@@ -204,6 +217,18 @@ Date to report for. Defaults to the current day.

Time to report for. Defaults to now.

=item B<mot> => I<\%hashref>

Modes of transport to show. Accepted keys are: B<ice> (ICE trains), B<ic_ec>
(IC and EC trains), B<d> (InterRegio and similarly fast trains), B<nv>
("Nahverkehr", mostly RegionalExpress trains), B<s> ("S-Bahn"), B<bus>,
B<ferry>, B<u> ("U-Bahn") and B<tram>.

Setting a mode (as hash key) to 1 includes it, 0 excludes it.  undef leaves it
at the default.

By default, the following are shown: ice, ic_ec, d, nv, s.

=back

=item $status->departures()