summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2013-12-11 23:13:38 +0100
committerDaniel Friesel <derf@finalrewind.org>2013-12-11 23:13:38 +0100
commit0736de7268d9ac8d5edef06cb8838e19d9bfa667 (patch)
treebdc26a20c4a8b8e5f6bd622d4f715d919f5d55fb
parent385eab07bef28d42e55bcab757f18864124523ab (diff)
Add -v/--via filter
-rwxr-xr-xbin/aseag-m9
-rw-r--r--lib/Travel/Status/DE/ASEAG.pm31
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<stop>
+
+Only show lines which will also service I<stop>. With B<-b>, I<stop> must be
+in the schedule before I<name>, with B<-f> it may be anywhere, with B<-a>
+(and by default) it must be after I<name>.
+
=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<name>.
+=item B<via> => I<vianame>
+
+Only return departures containing I<vianame> in their route. If B<stop> is set,
+I<vianame> must be in the route after the stop I<name>. If, in addition to
+that, B<full_routes> is set to B<before>, I<vianame> must be in the route
+before the stop I<name>. Respects B<fuzzy>. Implies C<< full_routes> => 'after' >> unless
+B<full_routes> is explicitly set to B<before> / B<after> / 1.
+
=back
=back