summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog1
-rwxr-xr-xbin/db-ris5
-rw-r--r--lib/Travel/Status/DE/DeutscheBahn.pm39
-rw-r--r--lib/Travel/Status/DE/DeutscheBahn/Result.pm18
4 files changed, 44 insertions, 19 deletions
diff --git a/Changelog b/Changelog
index 2560640..bd035fe 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,7 @@
git HEAD
* Result->route_interesting: Also consider airports
+ * Result: Add route_info accessor
Travel::Status::DE::DeutscheBahn 1.04 - Sun May 03 2015
diff --git a/bin/db-ris b/bin/db-ris
index 5ba1f16..911a444 100755
--- a/bin/db-ris
+++ b/bin/db-ris
@@ -90,6 +90,10 @@ sub display_result {
@{$line}[ 0 .. 5 ]
);
+ if ( $line->[7] ) {
+ print " " . $line->[7] . "\n";
+ }
+
if ($show_full_route) {
print "\n" . $line->[6] . "\n\n\n";
}
@@ -128,6 +132,7 @@ for my $d ( $status->results() ) {
$d->info,
join( "\n",
map { sprintf( '%-5s %s', @{$_} ) } $d->route_timetable ),
+ $d->route_info,
]
);
}
diff --git a/lib/Travel/Status/DE/DeutscheBahn.pm b/lib/Travel/Status/DE/DeutscheBahn.pm
index b3170e0..4b9534a 100644
--- a/lib/Travel/Status/DE/DeutscheBahn.pm
+++ b/lib/Travel/Status/DE/DeutscheBahn.pm
@@ -171,12 +171,13 @@ sub results {
my $re_morelink = qr{ date = (?<date> .. [.] .. [.] .. ) }x;
my @parts = (
- [ 'time', './td[@class="time"]' ],
- [ 'train', './td[3]' ],
- [ 'route', './td[@class="route"]' ],
- [ 'dest', './td[@class="route"]//a' ],
- [ 'platform', './td[@class="platform"]' ],
- [ 'info', './td[@class="ris"]' ],
+ [ 'time', './td[@class="time"]' ],
+ [ 'train', './td[3]' ],
+ [ 'route', './td[@class="route"]' ],
+ [ 'dest', './td[@class="route"]//a' ],
+ [ 'platform', './td[@class="platform"]' ],
+ [ 'info', './td[@class="ris"]' ],
+ [ 'routeinfo', './td[@class="route"]//span[@class="red bold"]' ],
);
@parts = map { [ $_->[0], XML::LibXML::XPathExpression->new( $_->[1] ) ] }
@@ -200,7 +201,7 @@ sub results {
my @via;
my $first = 1;
- my ( $time, $train, $route, $dest, $platform, $info )
+ my ( $time, $train, $route, $dest, $platform, $info, $routeinfo )
= map { get_node( $tr, @{$_} ) } @parts;
my $e_train_more = ( $tr->findnodes($xp_train_more) )[0];
@@ -214,10 +215,11 @@ sub results {
substr( $date, 6, 0 ) = '20';
- $platform //= q{};
- $info //= q{};
+ $platform //= q{};
+ $info //= q{};
+ $routeinfo //= q{};
- for my $str ( $time, $train, $dest, $platform, $info ) {
+ for my $str ( $time, $train, $dest, $platform, $info, $routeinfo ) {
$str =~ s/\n/ /mg;
$str =~ tr/ //s;
$str =~ s/^ +//;
@@ -240,14 +242,15 @@ sub results {
push(
@{ $self->{results} },
Travel::Status::DE::DeutscheBahn::Result->new(
- date => $date,
- time => $time,
- train => $train,
- route_raw => $route,
- route => \@via,
- route_end => $dest,
- platform => $platform,
- info_raw => $info,
+ date => $date,
+ time => $time,
+ train => $train,
+ route_raw => $route,
+ route => \@via,
+ route_end => $dest,
+ platform => $platform,
+ info_raw => $info,
+ routeinfo_raw => $routeinfo,
)
);
}
diff --git a/lib/Travel/Status/DE/DeutscheBahn/Result.pm b/lib/Travel/Status/DE/DeutscheBahn/Result.pm
index 00bfb96..bf300ed 100644
--- a/lib/Travel/Status/DE/DeutscheBahn/Result.pm
+++ b/lib/Travel/Status/DE/DeutscheBahn/Result.pm
@@ -11,7 +11,7 @@ use parent 'Class::Accessor';
our $VERSION = '1.04';
Travel::Status::DE::DeutscheBahn::Result->mk_ro_accessors(
- qw(date time train route_end route_raw platform info_raw));
+ qw(date time train route_end route_raw platform info_raw routeinfo_raw));
sub new {
my ( $obj, %conf ) = @_;
@@ -75,6 +75,17 @@ sub route {
return @stops;
}
+sub route_info {
+ my ($self) = @_;
+
+ my $route_info = $self->routeinfo_raw;
+
+ $route_info =~ s{ ^ [\s\n]+ }{}x;
+ $route_info =~ s{ [\s\n]+ $ }{}x;
+
+ return $route_info;
+}
+
sub route_interesting {
my ( $self, $max_parts ) = @_;
@@ -264,6 +275,11 @@ B<route_raw>.
Similar to B<route>. however, this function returns a list of array
references of the form C<< [ arrival time, station name ] >>.
+=item $result->route_info
+
+Returns a string containing information related to the train's route, such as
+"landslide between X and Y, expect delays".
+
=item $result->time
Returns the arrival/departure time as string in "hh:mm" format.