summaryrefslogtreecommitdiff
path: root/bin/db-iris
diff options
context:
space:
mode:
Diffstat (limited to 'bin/db-iris')
-rwxr-xr-xbin/db-iris112
1 files changed, 71 insertions, 41 deletions
diff --git a/bin/db-iris b/bin/db-iris
index c3161e5..08906e2 100755
--- a/bin/db-iris
+++ b/bin/db-iris
@@ -4,17 +4,15 @@ use warnings;
use 5.014;
use utf8;
-no if $] >= 5.018, warnings => 'experimental::smartmatch';
-
-our $VERSION = '1.51';
+our $VERSION = '1.96';
use DateTime;
use DateTime::Format::Strptime;
-use Encode qw(decode);
+use Encode qw(decode);
use Getopt::Long qw(:config no_ignore_case bundling);
use JSON;
-use List::Util qw(first max);
-use List::MoreUtils qw(none);
+use List::Util qw(first max);
+use List::MoreUtils qw(any none);
use Travel::Status::DE::IRIS;
use Travel::Status::DE::IRIS::Stations;
@@ -121,20 +119,18 @@ if ($time) {
}
for my $efield (@edata_pre) {
- given ($efield) {
- when ('a') { $edata{additional} = 1 }
- when ('c') { $edata{canceled} = 1 }
- when ('d') { $edata{delay} = 1 }
- when ('D') { $edata{delays} = 1 }
- when ('f') { $edata{fullroute} = 1 }
- when ('m') { $edata{messages} = 1 }
- when ('q') { $edata{qos} = 1 }
- when ('r') { $edata{route} = 1 }
- when ('R') { $edata{replacements} = 1 }
- when ('t') { $edata{times} = 1 }
- when ('!') { $edata{debug} = 1 }
- default { $edata{$efield} = 1 }
- }
+ if ( $efield eq 'a' ) { $edata{additional} = 1 }
+ elsif ( $efield eq 'c' ) { $edata{canceled} = 1 }
+ elsif ( $efield eq 'd' ) { $edata{delay} = 1 }
+ elsif ( $efield eq 'D' ) { $edata{delays} = 1 }
+ elsif ( $efield eq 'f' ) { $edata{fullroute} = 1 }
+ elsif ( $efield eq 'm' ) { $edata{messages} = 1 }
+ elsif ( $efield eq 'q' ) { $edata{qos} = 1 }
+ elsif ( $efield eq 'r' ) { $edata{route} = 1 }
+ elsif ( $efield eq 'R' ) { $edata{replacements} = 1 }
+ elsif ( $efield eq 't' ) { $edata{times} = 1 }
+ elsif ( $efield eq '!' ) { $edata{debug} = 1 }
+ else { $edata{$efield} = 1 }
}
if ($use_cache) {
@@ -239,7 +235,7 @@ sub get_station {
exit(1);
}
elsif ( @stations == 1 ) {
- return $stations[0][0];
+ return $stations[0][2];
}
else {
say STDERR "The input '$input_name' is ambiguous. Please choose one "
@@ -293,6 +289,9 @@ sub format_delay {
elsif ( $d->departure_is_cancelled ) {
$delay .= ' ⊖';
}
+ elsif ( $d->start < $datetime and not $d->has_realtime ) {
+ $delay = ' ?';
+ }
return $delay;
}
@@ -458,15 +457,33 @@ for my $d ( $status->results() ) {
# route may be incomplete, so check route_end as well
@via = ( $d->route_post, $d->route_end );
- if ( ( $filter_via and not( first { $_ =~ m{$filter_via}io } @via ) )
- or ( @grep_class and none { $_ ~~ \@grep_class } $d->classes )
- or ( @grep_platform and not( $d->platform ~~ \@grep_platform ) )
- or ( @grep_type and not( $d->type ~~ \@grep_type ) )
+ if ( ( $filter_via and not( first { $_ =~ m{$filter_via}io } @via ) )
or $d->is_wing )
{
next;
}
+ if ( @grep_platform and none { $d->platform eq $_ } @grep_platform ) {
+ next;
+ }
+
+ if ( @grep_type and none { $d->type eq $_ } @grep_type ) {
+ next;
+ }
+
+ if (@grep_class) {
+ my $skip = 1;
+ for my $class ( $d->classes ) {
+ if ( any { $class eq $_ } @grep_class ) {
+ $skip = 0;
+ last;
+ }
+ }
+ if ($skip) {
+ next;
+ }
+ }
+
my $delay = format_delay($d);
my $platformstr = $d->platform // q{};
@@ -479,8 +496,7 @@ for my $d ( $status->results() ) {
my $d_via = first {
$_->train_id eq $d->train_id
or ( $_->old_train_id and $_->old_train_id eq $d->train_id );
- }
- $status_via->results;
+ } $status_via->results;
if ( not $d_via
or not $d_via->sched_arrival
or $d_via->sched_arrival < $d->departure )
@@ -532,7 +548,7 @@ for my $d ( $status->results() ) {
push( @processed_wings, $wing->wing_id );
}
for my $wing ( $d->arrival_wings ) {
- if ( not $wing->wing_id ~~ \@processed_wings ) {
+ if ( none { $wing->wing_id eq $_ } @processed_wings ) {
my $wingdelay = format_delay($wing);
push(
@output,
@@ -571,24 +587,38 @@ B<db-iris> [B<-rx>] [B<-d> I<date>] [B<-o> I<output-flags>]
=head1 VERSION
-version 1.51
+version 1.96
=head1 DESCRIPTION
db-iris is an interface to the DeutscheBahn departure monitor
available at L<https://iris.noncd.db.de/wbt/js/index.html>.
-It requests all departures at I<station> and lists them on stdout, similar to
-the big departure screens installed at most main stations. I<station> can be
-a DS100 station code (such as "EE"), a normal station name
-(such as "Essen Hbf" or "Dortmund UniversitE<auml>t"), or an IBNR / european station
-number (such as 8000098). If no exact match is found, B<db-iris> will try to
-find station names similar to I<station>.
+It requests all trains departing from (or arriving at) I<station> in the next
+two hours and lists them on stdout. I<station> can be a DS100 station code
+(such as "EE"), a normal station name (such as "Essen Hbf" or "Dortmund
+UniversitE<auml>t"), or an IBNR / european station number (such as 8000098). If
+no exact match is found, B<db-iris> will try to find station names similar to
+I<station>.
+
+By default, db-iris shows the following data for each train:
+
+=over
+
+=item * scheduled departure time (see also B<-ot>, B<-r>).
+
+=item * delay in minutes, cancellation, or a question mark (C<< ? >>)
+indicating that no real-time data is available.
+
+=item * train line or number.
-An exclamation mark (C<< ! >>) next to a destination indicates that at least
-one stop on the train's route has been canceled. Use B<-oc> to see the canceled
-stops. An exclamation mark next to a platform indicates that it is not the
-scheduled one.
+=item * destination (see also B<-or>). An exclamation mark (C<< ! >>)
+indicates that at least one stop has been cancelled (see B<-oc>).
+
+=item * platform. An exclamation mark (C<< ! >>) indicates that it is not
+the scheduled one.
+
+=back
=head1 OPTIONS
@@ -627,7 +657,7 @@ in backwards-incompatible ways anytime.
=item B<-l>, B<--lookahead> I<int>
Do not return results which are more than I<int> minutes in the future.
-Defaults to 240 (4 hours).
+Defaults to 120 (2 hours).
Note that this is only an upper limit, not a guarantee to get every train
with a departure in less than I<int> minutes. This guarantee holds only for
@@ -828,7 +858,7 @@ There are no known bugs at the moment.
=head1 AUTHOR
-Copyright (C) 2013-2020 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt>
+Copyright (C) 2013-2024 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>
The station data used by this script is provided by DB
Station&Service AG, Europaplatz 1, 10557 Berlin, Germany and available