diff options
-rwxr-xr-x | bin/dbris-m | 35 | ||||
-rw-r--r-- | lib/Travel/Status/DE/DBRIS/Journey.pm | 13 |
2 files changed, 35 insertions, 13 deletions
diff --git a/bin/dbris-m b/bin/dbris-m index f8dd9f7..cc495a8 100755 --- a/bin/dbris-m +++ b/bin/dbris-m @@ -14,6 +14,7 @@ use List::Util qw(max); use Travel::Status::DE::DBRIS; my $developer_mode; +my $show_jid; my $use_cache = 1; my $cache; my ( $json_output, $raw_json_output ); @@ -29,12 +30,13 @@ my $output_bold = -t STDOUT ? "\033[1m" : q{}; my $output_reset = -t STDOUT ? "\033[0m" : q{}; GetOptions( - 'h|help' => sub { show_help(0) }, - 'V|version' => \&show_version, - 'cache!' => \$use_cache, - 'devmode' => \$developer_mode, - 'json' => \$json_output, - 'raw-json' => \$raw_json_output, + 'h|help' => sub { show_help(0) }, + 'j|with-jid' => \$show_jid, + 'V|version' => \&show_version, + 'cache!' => \$use_cache, + 'devmode' => \$developer_mode, + 'json' => \$json_output, + 'raw-json' => \$raw_json_output, ) or show_help(1); @@ -157,23 +159,36 @@ if ($json_output) { } if ( $opt{station} ) { - my $max_line = max map { length( $_->line ) } $status->results; - my $max_dest = max map { length( $_->dest_name ) } $status->results; + my $max_line = max map { length( $_->line ) } $status->results; + my $max_dest + = max map { length( $_->destination // q{} ) } $status->results; my $max_delay = max map { length( $_->delay // q{} ) } $status->results; + my $max_platform + = max map { length( $_->rt_platform // $_->platform // q{} ) } + $status->results; $max_delay += 1; for my $result ( $status->results ) { printf( - "%s %s %${max_line}s %${max_dest}s %s\n", + "%s %s %${max_line}s %${max_dest}s %${max_platform}s\n", $result->is_cancelled ? '--:--' : $result->dep->strftime('%H:%M'), $result->delay ? sprintf( "(%+${max_delay}d)", $result->delay ) : q{ } x ( $max_delay + 2 ), $result->line, - $result->dest_name, + $result->destination // $result->via_last // q{???}, $result->rt_platform // $result->platform // q{} ); + if ($show_jid) { + say $result->id; + } + for my $message ( $result->messages ) { + say $message->{text}; + } + if ( $show_jid or scalar $result->messages ) { + say q{}; + } } } elsif ( $opt{geoSearch} ) { diff --git a/lib/Travel/Status/DE/DBRIS/Journey.pm b/lib/Travel/Status/DE/DBRIS/Journey.pm index 6e420f4..47dd726 100644 --- a/lib/Travel/Status/DE/DBRIS/Journey.pm +++ b/lib/Travel/Status/DE/DBRIS/Journey.pm @@ -9,7 +9,7 @@ use parent 'Class::Accessor'; our $VERSION = '0.01'; Travel::Status::DE::DBRIS::Journey->mk_ro_accessors( - qw(type dep sched_dep rt_dep delay is_cancelled line stop_eva journey_id platform rt_platform dest_name via) + qw(type dep sched_dep rt_dep delay is_cancelled line stop_eva id platform rt_platform destination via via_last) ); sub new { @@ -21,12 +21,13 @@ sub new { my $ref = { type => $json->{verkehrmittel}{kurzText}, line => $json->{verkehrmittel}{mittelText}, - journey_id => $json->{journeyID}, + id => $json->{journeyId}, stop_eva => $json->{bahnhofsId}, - dest_name => $json->{terminus}, + destination => $json->{terminus}, platform => $json->{gleis}, rt_platform => $json->{ezGleis}, via => $json->{ueber}, + via_last => ( $json->{ueber} // [] )->[-1], }; bless( $ref, $obj ); @@ -69,6 +70,12 @@ sub route { return @{ $self->{route} }; } +sub messages { + my ($self) = @_; + + return @{ $self->{messages} // [] }; +} + sub TO_JSON { my ($self) = @_; |