diff options
author | Birte Kristina Friesel <birte.friesel@uos.de> | 2025-01-30 22:26:16 +0100 |
---|---|---|
committer | Birte Kristina Friesel <birte.friesel@uos.de> | 2025-01-30 22:26:16 +0100 |
commit | 99852d760a18a9d87acc832fd0557f630f5e69eb (patch) | |
tree | 36eebc183be9db91c4ac288e4b8b5467a866ec33 | |
parent | a956ddd5be0c79bf0263440bc9a32a4590340d00 (diff) |
parse and expose messages
-rwxr-xr-x | bin/dbris | 28 | ||||
-rw-r--r-- | lib/Travel/Routing/DE/DBRIS/Connection.pm | 25 |
2 files changed, 53 insertions, 0 deletions
@@ -19,6 +19,7 @@ my $mots; my ( $first_class, $passengers ); my $developer_mode; my ( $json_output, $raw_json_output ); +my $verbose; my $use_cache = 1; my $show_full_route; my $cache; @@ -43,6 +44,7 @@ GetOptions( 'l|language=s' => \$language, 'p|passengers=s' => \$passengers, 't|time=s' => \$time, + 'v|verbose' => \$verbose, 'V|version' => \&show_version, 'cache!' => \$use_cache, 'devmode' => \$developer_mode, @@ -316,6 +318,19 @@ for my $connection ( $ris->connections ) { : q{}, $header, ); + + if ($verbose) { + for my $note ( $connection->notes ) { + printf( "| %s (%s)\n", $note->{value}, $note->{key} ); + } + + for my $msg ( $connection->messages ) { + printf( "| %s\n", $msg->{text} ); + } + } + + say q{}; + for my $segment ( $connection->segments ) { if ( $segment->is_transfer ) { for my $note ( $segment->transfer_notes ) { @@ -382,6 +397,19 @@ for my $connection ( $ris->connections ) { $segment->arr_name, $segment->arr_platform ? q{ } . $segment->arr_platform : q{}, ); + + if ($verbose) { + for my $msg ( $segment->messages_ris ) { + printf( "| %s (%s)\n", $msg->{value}, $msg->{key} ); + } + for my $msg ( $segment->messages_him ) { + printf( "| %s\n", $msg->{text} ); + } + for my $msg ( $segment->messages_prio ) { + printf( "| %s\n", $msg->{text} ); + } + } + say q{}; } say q{---------------------------------------}; diff --git a/lib/Travel/Routing/DE/DBRIS/Connection.pm b/lib/Travel/Routing/DE/DBRIS/Connection.pm index 2ad46d8..d7c74f0 100644 --- a/lib/Travel/Routing/DE/DBRIS/Connection.pm +++ b/lib/Travel/Routing/DE/DBRIS/Connection.pm @@ -94,6 +94,19 @@ sub new { $ref->{$key} = $ref->{segments}[-1]{$key}; } + for my $note ( @{ $json->{risNotizen} // [] } ) { + push( @{ $ref->{notes} }, $note ); + if ( $note->{key} eq 'text.realtime.connection.cancelled' ) { + $ref->{is_cancelled} = 1; + } + elsif ( $note->{key} eq 'text.realtime.connection.brokentrip' ) { + $ref->{is_unlikely} = 1; + } + } + for my $message ( @{ $json->{messages} // [] } ) { + push( @{ $ref->{messages} }, $message ); + } + bless( $ref, $obj ); return $ref; @@ -105,6 +118,18 @@ sub segments { return @{ $self->{segments} // [] }; } +sub notes { + my ($self) = @_; + + return @{ $self->{notes} // [] }; +} + +sub messages { + my ($self) = @_; + + return @{ $self->{messages} // [] }; +} + sub TO_JSON { my ($self) = @_; |