summaryrefslogtreecommitdiff
path: root/lib/Travelynx.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travelynx.pm')
-rwxr-xr-xlib/Travelynx.pm45
1 files changed, 42 insertions, 3 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 76b4b7f..7a4b6ca 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -646,6 +646,7 @@ sub startup {
= $db->select( 'in_transit', '*', { user_id => $uid } )->hash;
if ( $has_arrived or $force ) {
+ delete $journey->{data};
$journey->{edited} = 0;
$journey->{checkout_time} = $now;
$db->insert( 'journeys', $journey );
@@ -1591,12 +1592,13 @@ sub startup {
my $tree;
my $traininfo = {
- station => {},
+ station => {},
+ messages => [],
};
# <SDay text="... &gt; ..."> is invalid HTML, but present in
# regardless. As it is the last tag, we just throw it away.
- $body =~ s{<SDay .*}{</Journey>}s;
+ $body =~ s{<SDay [^>]*/>}{}s;
eval { $tree = XML::LibXML->load_xml( string => $body ) };
if ($@) {
$self->app->log->warning("load_xml($url): $@");
@@ -1615,6 +1617,21 @@ sub startup {
};
}
+ for my $message ( $tree->findnodes('/Journey/HIMMessage') )
+ {
+ my $header = $message->getAttribute('header');
+ my $lead = $message->getAttribute('lead');
+ my $display = $message->getAttribute('display');
+ push(
+ @{ $traininfo->{messages} },
+ {
+ header => $header,
+ lead => $lead,
+ display => $display
+ }
+ );
+ }
+
$cache->freeze( $url, $traininfo );
$promise->resolve($traininfo);
}
@@ -1655,6 +1672,14 @@ sub startup {
$self->app->log->debug("add_route_timestamps");
+ my $extra_data = {
+ delay_msg => [
+ map { [ $_->[0]->epoch, $_->[1] ] } $train->delay_messages
+ ],
+ qos_msg =>
+ [ map { [ $_->[0]->epoch, $_->[1] ] } $train->qos_messages ],
+ };
+
my ( $trainlink, $route_data );
$self->get_hafas_json_p(
@@ -1743,9 +1768,15 @@ sub startup {
$station->[1]
= $route_data->{ $station->[0] };
}
+
+ $extra_data->{him_msg} = $traininfo2->{messages};
+
$db->update(
'in_transit',
- { route => JSON->new->encode($route) },
+ {
+ route => JSON->new->encode($route),
+ data => JSON->new->encode($extra_data)
+ },
{ user_id => $uid }
);
}
@@ -2139,6 +2170,7 @@ sub startup {
arr_platform => $in_transit->{arr_platform},
route_after => \@route_after,
messages => $in_transit->{messages},
+ extra_data => $in_transit->{data},
};
my @parsed_messages;
@@ -2148,6 +2180,13 @@ sub startup {
}
$ret->{messages} = [ reverse @parsed_messages ];
+ @parsed_messages = ();
+ for my $message ( @{ $ret->{extra_data}{qos_msg} // [] } ) {
+ my ( $ts, $msg ) = @{$message};
+ push( @parsed_messages, [ epoch_to_dt($ts), $msg ] );
+ }
+ $ret->{extra_data}{qos_msg} = [@parsed_messages];
+
for my $station (@route_after) {
if ( @{$station} > 1 ) {
my $times = $station->[1];