summaryrefslogtreecommitdiff
path: root/bin/db-wagenreihung
diff options
context:
space:
mode:
Diffstat (limited to 'bin/db-wagenreihung')
-rwxr-xr-xbin/db-wagenreihung107
1 files changed, 59 insertions, 48 deletions
diff --git a/bin/db-wagenreihung b/bin/db-wagenreihung
index 73bbdb4..5455e9e 100755
--- a/bin/db-wagenreihung
+++ b/bin/db-wagenreihung
@@ -4,7 +4,7 @@ use warnings;
use 5.020;
use utf8;
-our $VERSION = '0.11';
+our $VERSION = '0.18';
use Getopt::Long;
use List::Util qw(min);
@@ -65,48 +65,56 @@ if ( @trains != 1 ) {
}
my $wr = Travel::Status::DE::DBWagenreihung->new(
- departure => $trains[0]->sched_departure || $trains[0]->sched_arrival,
developer_mode => $developer_mode,
+ departure => $trains[0]->sched_departure || $trains[0]->sched_arrival,
+ eva => $trains[0]->station_eva,
+ train_type => $trains[0]->type,
train_number => $train_number,
);
+if ( $wr->errstr ) {
+ say STDERR $wr->errstr;
+ exit 2;
+}
+
printf(
- "%s: %s → %s\n",
- join( ' / ', map { $wr->train_type . ' ' . $_ } $wr->train_numbers ),
- join( ' / ', $wr->origins ),
+ "%s → %s\n",
+ join(
+ ' / ', map { $wr->train_type . ' ' . $_->{name} } $wr->train_numbers
+ ),
join(
' / ',
map {
- sprintf( '%s (%s)', $_->{name}, join( q{}, @{ $_->{sections} } ) )
+ sprintf( '%s (%s)', $_->{name}, join( q{}, @{ $_->{sectors} } ) )
} $wr->destinations
),
);
-printf( "%s Gleis %s\n\n", $wr->station_name, $wr->platform );
+printf( "Gleis %s\n\n", $wr->platform );
-for my $section ( $wr->sections ) {
- my $section_length = $section->length_percent;
- my $spacing_left = int( ( $section_length - 2 ) / 2 ) - 1;
- my $spacing_right = int( ( $section_length - 2 ) / 2 );
+for my $sector ( $wr->sectors ) {
+ my $sector_length = $sector->length_percent;
+ my $spacing_left = int( ( $sector_length - 2 ) / 2 ) - 1;
+ my $spacing_right = int( ( $sector_length - 2 ) / 2 );
- if ( $section_length % 2 ) {
+ if ( $sector_length % 2 ) {
$spacing_left++;
}
printf( "▏%s%s%s▕",
- ' ' x $spacing_left,
- $section->name,
- ' ' x $spacing_right );
+ ( $spacing_left >= 0 ) ? ' ' x $spacing_left : q{},
+ $sector->name, ( $spacing_right >= 0 ) ? ' ' x $spacing_right : q{} );
}
print "\n";
-my @start_percentages = map { $_->{position}{start_percent} } $wr->wagons;
-print ' ' x ( ( min @start_percentages ) - 1 );
+my @start_percentages = map { $_->start_percent } $wr->carriages;
+if ( my $min_percentage = min @start_percentages ) {
+ print ' ' x ( $min_percentage - 1 );
+}
print $wr->direction == 100 ? '>' : '<';
-for my $wagon ( $wr->wagons ) {
- my $wagon_length
- = $wagon->{position}->{end_percent} - $wagon->{position}->{start_percent};
+for my $wagon ( $wr->carriages ) {
+ my $wagon_length = $wagon->length_percent;
my $spacing_left = int( $wagon_length / 2 ) - 2;
my $spacing_right = int( $wagon_length / 2 ) - 1;
@@ -142,29 +150,33 @@ for my $wagon ( $wr->wagons ) {
print $wr->direction == 100 ? '>' : '<';
print "\n\n";
-for my $desc ( $wr->train_descriptions ) {
- if ( $desc->{text} ) {
- printf( "%s (%s)\n",
- $desc->{text}, join( q{}, @{ $desc->{sections} } ) );
+for my $group ( $wr->groups ) {
+ printf( "%s%s%s\n",
+ $group->description || 'Zug',
+ $group->designation ? ' „' . $group->designation . '“' : q{},
+ $group->has_sectors ? ' (' . join( q{}, $group->sectors ) . ')' : q{} );
+ printf( "%s %s → %s\n\n",
+ $group->train_type, $group->train_no, $group->destination );
+
+ for my $wagon ( $group->carriages ) {
+ printf(
+ "%3s: %3s %10s %s\n",
+ $wagon->is_closed ? 'X'
+ : $wagon->is_locomotive ? 'Lok'
+ : $wagon->number || '?',
+ $wagon->model || '???',
+ $wagon->type,
+ join( q{ }, $wagon->attributes )
+ );
}
-}
-
-say "";
-
-for my $wagon ( $wr->wagons ) {
- printf(
- "%3s: %3s %10s %s\n",
- $wagon->is_closed ? 'X' : ( $wagon->number || '?' ),
- $wagon->model || '???',
- $wagon->type, join( q{ }, $wagon->attributes )
- );
+ say "";
}
__END__
=head1 NAME
-db-wagenreihung - Interface to Deutsche Bahn Wagon Order API
+db-wagenreihung - Interface to Deutsche Bahn carriage formation API
=head1 SYNOPSIS
@@ -172,21 +184,20 @@ B<db-wagenreihung> I<station> I<train-number>
=head1 VERSION
-version 0.11
+version 0.18
This is beta software: API and output format may change without notice.
=head1 DESCRIPTION
-db-wagenreihung shows the wagon order of train I<train-number> at station
-I<station> (must be a name or DS100 code) as reported by the Deutsche Bahn
-Wagon Order API. As of April 2020, long-distance IC/EC/ICFE trains are widely
-supported, and some regions (e.g. Stuttgart/Karlsruhe) also provide wagon
-orders for select regional trains. Data accuracy varies, but seems to be
-improving over time.
+db-wagenreihung shows the carriage formation (also known as coach sequence) of
+train I<train-number> at station I<station> (must be a name or DS100 code) as
+reported by the Deutsche Bahn Wagenreihung API. As of April 2024, it has mature
+support for long-distance (IC/EC/ICE) trains and a growing number of regional
+transport providers that also offer mostly correct carriage formation data.
-It is not possible to request the wagon order at a train's terminus station.
-This is a known limitation.
+It is not possible to request the carriage formation at a train's terminus
+station. This is a known limitation.
The departure of I<train-number> must be in the time range between now and
two hours in the future.
@@ -197,11 +208,11 @@ two hours in the future.
=item db-wagenreihung 'Essen Hbf' 723
-Show wagon order of ICE 723 at Essen Hbf
+Show carriage formation of ICE 723 at Essen Hbf
=item db-wagenreihung TS 3259
-Show wagon order of IRE 3259 at Stuttgart Hbf
+Show carriage formation of IRE 3259 at Stuttgart Hbf
=back
@@ -219,7 +230,7 @@ Show wagon order of IRE 3259 at Stuttgart Hbf
=head1 AUTHOR
-Copyright (C) 2018-2020 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>
+Copyright (C) 2018-2024 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>
=head1 LICENSE