From 56d095e4975b3d0b4010738ebd05597b6503f4af Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 28 Feb 2016 19:38:41 +0100 Subject: preparations for optional emma message support --- bin/db-iris | 16 ++++++++++++++++ lib/Travel/Status/DE/IRIS.pm | 11 +++++++++++ lib/Travel/Status/DE/IRIS/Result.pm | 30 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/bin/db-iris b/bin/db-iris index b90c99b..5efd3ea 100755 --- a/bin/db-iris +++ b/bin/db-iris @@ -23,6 +23,7 @@ my $datetime = DateTime->now( time_zone => 'Europe/Berlin' ); my $developer_mode = 0; my $realtime = 0; my $with_related = 1; +my $emma_url; my ( $filter_via, $track_via, $status_via ); my ( @grep_class, @grep_type, @grep_platform ); my ( %edata, @edata_pre ); @@ -47,6 +48,7 @@ GetOptions( 'V|track-via=s' => \$track_via, 'x|exact|no-related' => sub { $with_related = 0 }, 'devmode' => \$developer_mode, + 'emma=s' => \$emma_url, 'version' => \&show_version, ) or show_help(1); @@ -93,6 +95,7 @@ for my $efield (@edata_pre) { when ('D') { $edata{delays} = 1 } when ('f') { $edata{fullroute} = 1 } when ('m') { $edata{messages} = 1 } + when ('M') { $edata{trackinfo} = 1 } when ('q') { $edata{qos} = 1 } when ('r') { $edata{route} = 1 } when ('R') { $edata{replacements} = 1 } @@ -108,6 +111,7 @@ my $status = Travel::Status::DE::IRIS->new( lookahead => $lookahead, station => $station, with_related => $with_related, + emma_url => $emma_url, ); if ($track_via) { @@ -275,6 +279,18 @@ sub display_result { } } + if ( $edata{trackinfo} ) { + for my $message ( $d->track_messages ) { + + printf( + " %s → %s %s\n", + $message->[0]->strftime('%d.%m. %H:%M'), + $message->[1]->strftime('%d.%m. %H:%M'), + $message->[3] + ); + } + } + if ( $edata{messages} ) { for my $message ( $d->messages ) { diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm index 937bb65..3519952 100644 --- a/lib/Travel/Status/DE/IRIS.pm +++ b/lib/Travel/Status/DE/IRIS.pm @@ -330,9 +330,11 @@ sub get_realtime { my $e_ar = ( $s->findnodes('./ar') )[0]; my $e_dp = ( $s->findnodes('./dp') )[0]; my @e_refs = $s->findnodes('./ref/tl'); + my @e_tms = $s->findnodes('./m'); my @e_ms = $s->findnodes('.//m'); my %messages; + my %track_messages; my $result = first { $_->raw_id eq $id } $self->results; @@ -362,8 +364,17 @@ sub get_realtime { $messages{$msgid} = [ $ts, $type, $value ]; } } + for my $e_tm (@e_tms) { + my $type = $e_tm->getAttribute('t'); + my $msgid = $e_tm->getAttribute('id'); + my $ts = $e_tm->getAttribute('ts'); + my $from = $e_tm->getAttribute('from'); + my $to = $e_tm->getAttribute('to'); + $track_messages{$msgid} = [ $ts, $from, $to, $type, $msgid ]; + } $result->set_messages(%messages); + $result->set_track_messages(%track_messages); # note: A departure may also have a ./tl attribute. However, we do # not need to process it because it only matters for departures which diff --git a/lib/Travel/Status/DE/IRIS/Result.pm b/lib/Travel/Status/DE/IRIS/Result.pm index 63e0c40..153db87 100644 --- a/lib/Travel/Status/DE/IRIS/Result.pm +++ b/lib/Travel/Status/DE/IRIS/Result.pm @@ -305,6 +305,14 @@ sub set_messages { return $self; } +sub set_track_messages { + my ( $self, %track_messages ) = @_; + + $self->{track_messages} = \%track_messages; + + return $self; +} + sub set_realtime { my ( $self, $xmlobj ) = @_; @@ -469,6 +477,28 @@ sub delay_messages { return @ret; } +sub track_messages { + my ($self) = @_; + + my @keys = reverse sort keys %{ $self->{track_messages} }; + my @msgs = map { $self->{track_messages}{$_} } @keys; + my @ret; + + for my $msg (@msgs) { + push( + @ret, + [ + $self->parse_ts( $msg->[0] ), + $self->parse_ts( $msg->[1] ), + $self->parse_ts( $msg->[2] ), + $msg->[4] + ] + ); + } + + return @ret; +} + sub arrival_wings { my ($self) = @_; -- cgit v1.2.3