summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2013-12-11 01:15:11 +0100
committerDaniel Friesel <derf@finalrewind.org>2013-12-11 01:15:11 +0100
commitb5d492e649d266ae78ceb1bd7d04d22fc79a9ef9 (patch)
treeaada3a158260eef91bcff06b0826aa746ee37bce
parentad4b1b28b4f35a4fa72453994a150f11cad03182 (diff)
-f (--full-route) support
-rwxr-xr-xbin/aseag-m33
-rw-r--r--lib/Travel/Status/DE/ASEAG.pm63
-rw-r--r--lib/Travel/Status/DE/ASEAG/Result.pm4
3 files changed, 80 insertions, 20 deletions
diff --git a/bin/aseag-m b/bin/aseag-m
index c25c438..1fb593f 100755
--- a/bin/aseag-m
+++ b/bin/aseag-m
@@ -14,11 +14,13 @@ use List::Util qw(max);
use Travel::Status::DE::ASEAG;
my (@grep_lines);
+my $show_full_route = 0;
GetOptions(
- 'h|help' => sub { show_help(0) },
- 'l|line=s@' => \@grep_lines,
- 'V|version' => \&show_version,
+ 'h|help' => sub { show_help(0) },
+ 'f|full-route' => \$show_full_route,
+ 'l|line=s@' => \@grep_lines,
+ 'V|version' => \&show_version,
) or show_help(1);
@@ -31,7 +33,10 @@ if ( @ARGV != 1 ) {
my ($stop_name) = @ARGV;
-my $status = Travel::Status::DE::ASEAG->new( name => $stop_name, );
+my $status = Travel::Status::DE::ASEAG->new(
+ name => $stop_name,
+ full_routes => $show_full_route
+);
sub show_help {
my ($code) = @_;
@@ -66,6 +71,10 @@ sub display_result {
join( q{ }, ( map { "%-${_}s" } @line_length ) ) . "\n",
@{$line}[ 0 .. 2 ]
);
+
+ if ($show_full_route) {
+ print "\n" . $line->[3] . "\n\n\n";
+ }
}
return;
@@ -82,7 +91,17 @@ sub show_results {
next;
}
- push( @output, [ $dtime, $d->line, $d->destination ] );
+ push(
+ @output,
+ [
+ $dtime,
+ $d->line,
+ $d->destination,
+ join( "\n",
+ map { sprintf( '%-8s %s', @{$_} ) }
+ @{ $d->route_timetable } )
+ ]
+ );
}
display_result(@output);
@@ -119,6 +138,10 @@ B<aseag-m> lists upcoming bus departures at the ASEAG stop I<name>.
=over
+=item B<-f>, B<--full-route>
+
+Display complete routes (including arrival times) of all buses.
+
=item B<-l>, B<--line> I<lines>
Only show departures of I<lines> (comma-separatad list, option may be
diff --git a/lib/Travel/Status/DE/ASEAG.pm b/lib/Travel/Status/DE/ASEAG.pm
index ed504a2..488959e 100644
--- a/lib/Travel/Status/DE/ASEAG.pm
+++ b/lib/Travel/Status/DE/ASEAG.pm
@@ -20,9 +20,10 @@ sub new {
my $ua = LWP::UserAgent->new(%opt);
my $self = {
- fuzzy => $opt{fuzzy} // 1,
- stop => $opt{name},
- post => {
+ full_routes => $opt{full_routes} // 0,
+ fuzzy => $opt{fuzzy} // 1,
+ stop => $opt{name},
+ post => {
ReturnList =>
'lineid,linename,directionid,destinationtext,vehicleid,'
. 'tripid,estimatedtime,stopid,stoppointname'
@@ -41,7 +42,17 @@ sub new {
return $self;
}
- $self->{raw} = $response->decoded_content;
+ $self->{raw_str} = $response->decoded_content;
+
+ for my $dep ( split( /\r\n/, $self->{raw_str} ) ) {
+ $dep =~ s{^\[}{};
+ $dep =~ s{\]$}{};
+
+ # first field == 4 => version information, no departure
+ if ( substr( $dep, 0, 1 ) != 4 ) {
+ push( @{ $self->{raw_list} }, [ split( /"?,"?/, $dep ) ] );
+ }
+ }
return $self;
}
@@ -49,7 +60,17 @@ sub new {
sub new_from_xml {
my ( $class, %opt ) = @_;
- my $self = { raw => $opt{raw}, };
+ my $self = { raw_str => $opt{raw_str}, };
+
+ for my $dep ( split( /\r\n/, $self->{raw} ) ) {
+ $dep =~ s{^\[}{};
+ $dep =~ s{\]$}{};
+
+ # first field == 4 => version information, no departure
+ if ( substr( $dep, 0, 1 ) != 4 ) {
+ push( @{ $self->{raw_list} }, [ split( /"?,"?/, $dep ) ] );
+ }
+ }
return bless( $self, $class );
}
@@ -97,19 +118,13 @@ sub results {
my $dt_now = DateTime->now( time_zone => 'Europe/Berlin' );
- for my $dep ( split( /\r\n/, $self->{raw} ) ) {
- $dep =~ s{^\[}{};
- $dep =~ s{\]$}{};
+ for my $dep ( @{ $self->{raw_list} } ) {
my (
$u1, $stopname, $stopid, $lineid, $linename,
$u2, $dest, $vehicleid, $tripid, $timestamp
- ) = split( /"?,"?/, $dep );
-
- # version information
- if ( $u1 == 4 ) {
- next;
- }
+ ) = @{$dep};
+ my @route;
if ( $self->{stop} and not $self->is_my_stop($stopname) ) {
next;
@@ -120,6 +135,25 @@ sub results {
next;
}
+ if ( $self->{full_routes} ) {
+ @route = map { [ $_->[9] / 1000, $_->[1] ] }
+ grep { $_->[8] == $tripid } @{ $self->{raw_list} };
+
+ @route = map { $_->[0] }
+ sort { $a->[1] <=> $b->[1] }
+ map { [ $_, $_->[0] ] } @route;
+
+ @route = map {
+ [
+ DateTime->from_epoch(
+ epoch => $_->[0],
+ time_zone => 'Europe/Berlin'
+ )->hms,
+ decode( 'UTF-8', $_->[1] )
+ ]
+ } @route;
+ }
+
my $dt_dep = DateTime->from_epoch(
epoch => $timestamp / 1000,
time_zone => 'Europe/Berlin'
@@ -138,6 +172,7 @@ sub results {
$dt_dep->subtract_datetime($dt_now)->in_units('minutes'),
countdown_sec =>
$dt_dep->subtract_datetime($dt_now)->in_units('seconds'),
+ route_timetable => [@route],
)
);
}
diff --git a/lib/Travel/Status/DE/ASEAG/Result.pm b/lib/Travel/Status/DE/ASEAG/Result.pm
index 05045b1..47d9d0c 100644
--- a/lib/Travel/Status/DE/ASEAG/Result.pm
+++ b/lib/Travel/Status/DE/ASEAG/Result.pm
@@ -9,7 +9,9 @@ use parent 'Class::Accessor';
our $VERSION = '0.00';
Travel::Status::DE::ASEAG::Result->mk_ro_accessors(
- qw(countdown countdown_sec date datetime destination line line_id time));
+ qw(countdown countdown_sec date datetime destination line line_id
+ route_timetable time)
+);
sub new {
my ( $obj, %conf ) = @_;