From 0736de7268d9ac8d5edef06cb8838e19d9bfa667 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 11 Dec 2013 23:13:38 +0100 Subject: Add -v/--via filter --- bin/aseag-m | 9 +++++++++ lib/Travel/Status/DE/ASEAG.pm | 31 ++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/bin/aseag-m b/bin/aseag-m index 62195d5..2c4e655 100755 --- a/bin/aseag-m +++ b/bin/aseag-m @@ -16,6 +16,7 @@ use Travel::Status::DE::ASEAG; my (@grep_lines); my $full_route = 0; my $hide_past = 1; +my $via; GetOptions( 'a|route-after' => sub { $full_route = 'after' }, @@ -24,6 +25,7 @@ GetOptions( 'f|full-route' => \$full_route, 'l|line=s@' => \@grep_lines, 'p|with-past' => sub { $hide_past = 0 }, + 'v|via=s' => \$via, 'V|version' => \&show_version, ) or show_help(1); @@ -90,6 +92,7 @@ sub show_results { full_routes => $full_route, hide_past => $hide_past, stop => $stop_name, + via => $via, ) ) { @@ -169,6 +172,12 @@ repeated) Also show departures in the past. Also appleas to the route information of B<-a> / B<-b> / B<-f>. +=item B<-v>, B<--via> I + +Only show lines which will also service I. With B<-b>, I must be +in the schedule before I, with B<-f> it may be anywhere, with B<-a> +(and by default) it must be after I. + =item B<-V>, B<--version> Show version information. diff --git a/lib/Travel/Status/DE/ASEAG.pm b/lib/Travel/Status/DE/ASEAG.pm index 3a22652..ed17d98 100644 --- a/lib/Travel/Status/DE/ASEAG.pm +++ b/lib/Travel/Status/DE/ASEAG.pm @@ -11,8 +11,9 @@ our $VERSION = '0.00'; use Carp qw(confess cluck); use DateTime; use Encode qw(encode decode); -use Travel::Status::DE::ASEAG::Result; +use List::MoreUtils qw(none); use LWP::UserAgent; +use Travel::Status::DE::ASEAG::Result; sub new { my ( $class, %opt ) = @_; @@ -24,6 +25,7 @@ sub new { fuzzy => $opt{fuzzy} // 1, hide_past => $opt{hide_past} // 1, stop => $opt{stop}, + via => $opt{via}, post => { ReturnList => 'lineid,linename,directionid,destinationtext,vehicleid,' @@ -120,10 +122,15 @@ sub results { my $fuzzy = $opt{fuzzy} // $self->{fuzzy} // 1; my $hide_past = $opt{hide_past} // $self->{hide_past} // 1; my $stop = $opt{stop} // $self->{stop}; + my $via = $opt{via} // $self->{via}; my $dt_now = DateTime->now( time_zone => 'Europe/Berlin' ); my $ts_now = $dt_now->epoch; + if ($via) { + $full_routes ||= 'after'; + } + for my $dep ( @{ $self->{raw_list} } ) { my ( @@ -155,10 +162,6 @@ sub results { @route = map { [ $_->[9] / 1000, $_->[1] ] } grep { $_->[8] == $tripid } @{ $self->{raw_list} }; - if ($hide_past) { - @route = grep { $_->[0] >= $ts_now } @route; - } - if ( $full_routes eq 'before' ) { @route = grep { $_->[0] < $ts_dep } @route; } @@ -166,6 +169,16 @@ sub results { @route = grep { $_->[0] > $ts_dep } @route; } + if ( $via + and none { $self->is_my_stop( $_->[1], $via, $fuzzy ) } @route ) + { + next; + } + + if ($hide_past) { + @route = grep { $_->[0] >= $ts_now } @route; + } + @route = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, $_->[0] ] } @route; @@ -292,6 +305,14 @@ Do not include past departures in the result list and the computed timetables. Only return departures at stop I. +=item B => I + +Only return departures containing I in their route. If B is set, +I must be in the route after the stop I. If, in addition to +that, B is set to B, I must be in the route +before the stop I. Respects B. Implies C<< full_routes> => 'after' >> unless +B is explicitly set to B / B / 1. + =back =back -- cgit v1.2.3