summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-12-26 14:00:54 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2024-12-26 14:00:54 +0100
commit7caeab689baf8390e12915264838c1a0da73e2ef (patch)
tree884111720493adeb6e030658ecb999364186775e
parent0c91406149c1ed3180bac678d679dc5ccb2140e5 (diff)
journey: parse trip day and attributes
-rwxr-xr-xbin/dbris-m9
-rw-r--r--lib/Travel/Status/DE/DBRIS.pm8
-rw-r--r--lib/Travel/Status/DE/DBRIS/Journey.pm14
3 files changed, 27 insertions, 4 deletions
diff --git a/bin/dbris-m b/bin/dbris-m
index 2049f2d..bf75a29 100755
--- a/bin/dbris-m
+++ b/bin/dbris-m
@@ -211,8 +211,7 @@ elsif ( $opt{journey} ) {
}
}
- say $trip->train;
- say q{};
+ printf( "%s am %s\n\n", $trip->train, $trip->day->strftime('%d.%m.%Y') );
for my $stop ( $trip->route ) {
if ( $stop == $mark_stop ) {
@@ -242,6 +241,12 @@ elsif ( $opt{journey} ) {
print($output_reset);
}
}
+ if ( $trip->attributes ) {
+ say q{};
+ }
+ for my $attr ( $trip->attributes ) {
+ say $attr->{value};
+ }
if ( $trip->messages ) {
say q{};
}
diff --git a/lib/Travel/Status/DE/DBRIS.pm b/lib/Travel/Status/DE/DBRIS.pm
index 66790b2..6221622 100644
--- a/lib/Travel/Status/DE/DBRIS.pm
+++ b/lib/Travel/Status/DE/DBRIS.pm
@@ -95,6 +95,11 @@ sub new {
time_zone => 'Europe/Berlin',
);
+ $self->{strpdate_obj} //= DateTime::Format::Strptime->new(
+ pattern => '%Y-%m-%d',
+ time_zone => 'Europe/Berlin',
+ );
+
my $json = $self->{json} = JSON->new->utf8;
if ( $conf{async} ) {
@@ -272,7 +277,8 @@ sub parse_journey {
$self->{result} = Travel::Status::DE::DBRIS::Journey->new(
json => $self->{raw_json},
- strptime_obj => $self->{strptime_obj}
+ strpdate_obj => $self->{strpdate_obj},
+ strptime_obj => $self->{strptime_obj},
);
}
diff --git a/lib/Travel/Status/DE/DBRIS/Journey.pm b/lib/Travel/Status/DE/DBRIS/Journey.pm
index c4f7df6..4900809 100644
--- a/lib/Travel/Status/DE/DBRIS/Journey.pm
+++ b/lib/Travel/Status/DE/DBRIS/Journey.pm
@@ -10,15 +10,17 @@ use Travel::Status::DE::DBRIS::Location;
our $VERSION = '0.01';
-Travel::Status::DE::DBRIS::Journey->mk_ro_accessors(qw(train is_cancelled));
+Travel::Status::DE::DBRIS::Journey->mk_ro_accessors(qw(day train is_cancelled));
sub new {
my ( $obj, %opt ) = @_;
my $json = $opt{json};
+ my $strpdate = $opt{strpdate_obj};
my $strptime = $opt{strptime_obj};
my $ref = {
+ day => $strpdate->parse_datetime( $json->{reisetag} ),
train => $json->{zugName},
is_cancelled => $json->{cancelled},
raw_route => $json->{halte},
@@ -31,6 +33,10 @@ sub new {
push( @{ $ref->{messages} }, $message );
}
+ for my $attr ( @{ $json->{zugattribute} // [] } ) {
+ push( @{ $ref->{attributes} }, $attr );
+ }
+
return $ref;
}
@@ -53,6 +59,12 @@ sub route {
return @{ $self->{route} };
}
+sub attributes {
+ my ($self) = @_;
+
+ return @{ $self->{attributes} // [] };
+}
+
sub messages {
my ($self) = @_;