summaryrefslogtreecommitdiff
path: root/bin/dbwagenreihung
diff options
context:
space:
mode:
Diffstat (limited to 'bin/dbwagenreihung')
-rwxr-xr-xbin/dbwagenreihung66
1 files changed, 35 insertions, 31 deletions
diff --git a/bin/dbwagenreihung b/bin/dbwagenreihung
index dafefe3..fe0961a 100755
--- a/bin/dbwagenreihung
+++ b/bin/dbwagenreihung
@@ -10,90 +10,94 @@ use List::Util qw(min);
use Travel::Status::DE::IRIS;
use Travel::Status::DE::DBWagenreihung;
-my ($station, $train_number) = @ARGV;
+my ( $station, $train_number ) = @ARGV;
-my $res = Travel::Status::DE::IRIS->new(station => $station, with_related => 1);
+my $res = Travel::Status::DE::IRIS->new(
+ station => $station,
+ with_related => 1
+);
-if ($res->errstr) {
+if ( $res->errstr ) {
say STDERR $res->errstr;
exit 1;
}
my @trains = grep { $_->train_no eq $train_number } $res->results;
-if (@trains != 1) {
+if ( @trains != 1 ) {
say STDERR "Unable to find train in reported departures";
exit 1;
}
my $wr = Travel::Status::DE::DBWagenreihung->new(
- departure => $trains[0]->sched_departure,
+ departure => $trains[0]->sched_departure,
developer_mode => 1,
- train_number => $train_number,
+ train_number => $train_number,
);
-for my $section ($wr->sections) {
+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);
+ my $spacing_left = int( ( $section_length - 2 ) / 2 ) - 1;
+ my $spacing_right = int( ( $section_length - 2 ) / 2 );
- if ($section_length % 2) {
+ if ( $section_length % 2 ) {
$spacing_left++;
}
- printf("|%s%s%s|",
+ printf( "|%s%s%s|",
' ' x $spacing_left,
$section->name,
- ' ' x $spacing_right
- );
+ ' ' x $spacing_right );
}
print "\n";
my @start_percentages = map { $_->{position}{start_percent} } $wr->wagons;
-print ' ' x ((min @start_percentages) - 1);
+print ' ' x ( ( min @start_percentages ) - 1 );
print '[';
-for my $wagon ($wr->wagons) {
- my $wagon_length = $wagon->{position}->{end_percent} - $wagon->{position}->{start_percent};
- my $spacing_left = int($wagon_length / 2) - 2;
- my $spacing_right = int($wagon_length / 2) - 1;
+for my $wagon ( $wr->wagons ) {
+ my $wagon_length
+ = $wagon->{position}->{end_percent} - $wagon->{position}->{start_percent};
+ my $spacing_left = int( $wagon_length / 2 ) - 2;
+ my $spacing_right = int( $wagon_length / 2 ) - 1;
- if ($wagon_length % 2) {
+ if ( $wagon_length % 2 ) {
$spacing_left++;
}
my $wagon_desc = $wagon->number || '?';
- if ($wagon->is_locomotive or $wagon->is_powercar) {
+ if ( $wagon->is_locomotive or $wagon->is_powercar ) {
$wagon_desc = '<->';
}
- printf("%s%3s%s", ' ' x $spacing_left, $wagon_desc, ' ' x $spacing_right);
+ printf( "%s%3s%s", ' ' x $spacing_left, $wagon_desc, ' ' x $spacing_right );
}
print "]\n";
-print ' ' x (min @start_percentages);
-for my $wagon ($wr->wagons) {
- my $wagon_length = $wagon->{position}->{end_percent} - $wagon->{position}->{start_percent};
- my $spacing_left = int($wagon_length / 2) - 2;
- my $spacing_right = int($wagon_length / 2) - 1;
+print ' ' x ( min @start_percentages );
+for my $wagon ( $wr->wagons ) {
+ my $wagon_length
+ = $wagon->{position}->{end_percent} - $wagon->{position}->{start_percent};
+ my $spacing_left = int( $wagon_length / 2 ) - 2;
+ my $spacing_right = int( $wagon_length / 2 ) - 1;
- if ($wagon_length % 2) {
+ if ( $wagon_length % 2 ) {
$spacing_left++;
}
my $class = '';
- if ($wagon->class_type == 1) {
+ if ( $wagon->class_type == 1 ) {
$class = ' 1 ';
}
- elsif ($wagon->class_type == 2) {
+ elsif ( $wagon->class_type == 2 ) {
$class = ' 2 ';
}
- elsif ($wagon->class_type == 12) {
+ elsif ( $wagon->class_type == 12 ) {
$class = '1/2';
}
- printf("%s%3s%s", ' ' x $spacing_left, $class, ' ' x $spacing_right);
+ printf( "%s%3s%s", ' ' x $spacing_left, $class, ' ' x $spacing_right );
}
print "\n";