diff options
-rwxr-xr-x | bin/ura-m | 5 | ||||
-rw-r--r-- | lib/Travel/Status/DE/URA.pm | 37 |
2 files changed, 41 insertions, 1 deletions
@@ -93,6 +93,7 @@ my $status = Travel::Status::DE::URA->new( developer_mode => $developer_mode, ura_base => $ura_base, ura_version => $ura_version, + with_messages => 1, ); sub show_help { @@ -211,6 +212,10 @@ sub show_results { my $dt_format = DateTime::Format::Duration->new( pattern => $strfrel_format ); + for my $m ( $status->messages_by_stop_name($stop_name) ) { + printf( "# %s\n", $m ); + } + for my $d ( $status->results( calculate_routes => $calculate_routes, diff --git a/lib/Travel/Status/DE/URA.pm b/lib/Travel/Status/DE/URA.pm index f290e53..be405c2 100644 --- a/lib/Travel/Status/DE/URA.pm +++ b/lib/Travel/Status/DE/URA.pm @@ -63,6 +63,9 @@ sub new { }, }; + if ( $opt{with_messages} ) { + $self->{post}{ReturnList} .= ',messagetext,messagetype'; + } if ( $opt{with_stops} ) { $self->{post}{StopAlso} = 'True'; } @@ -158,7 +161,20 @@ sub parse_raw_data { ); } } - if ( $type == TYPE_PREDICTION ) { + elsif ( $type == TYPE_MESSAGE ) { + push( + @{ $self->{messages} }, + { + stop_name => $fields[1], + stop_id => $fields[2], + + # 0 = long text. 2 = short text for station displays? + type => $fields[6], + text => $fields[7], + } + ); + } + elsif ( $type == TYPE_PREDICTION ) { push( @{ $self->{stop_names} }, $fields[1] ); } } @@ -193,6 +209,25 @@ sub errstr { return $self->{errstr}; } +sub messages_by_stop_id { + my ( $self, $stop_id ) = @_; + + my @messages = grep { $_->{stop_id} == $stop_id } @{ $self->{messages} }; + @messages = map { $_->{text} } @messages; + + return @messages; +} + +sub messages_by_stop_name { + my ( $self, $stop_name ) = @_; + + my @messages + = grep { $_->{stop_name} eq $stop_name } @{ $self->{messages} }; + @messages = map { $_->{text} } @messages; + + return @messages; +} + sub results { my ( $self, %opt ) = @_; my @results; |