From 0e8352da3e31cb0fbedd3e50d21efe3a64866219 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 26 Dec 2018 09:39:03 +0100 Subject: rename dbwagenreihung to db-wagenreihung --- bin/db-wagenreihung | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/dbwagenreihung | 121 ---------------------------------------------------- 2 files changed, 121 insertions(+), 121 deletions(-) create mode 100755 bin/db-wagenreihung delete mode 100755 bin/dbwagenreihung diff --git a/bin/db-wagenreihung b/bin/db-wagenreihung new file mode 100755 index 0000000..100f4b1 --- /dev/null +++ b/bin/db-wagenreihung @@ -0,0 +1,121 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.020; +use utf8; + +our $VERSION = '0.00'; + +use Getopt::Long; +use List::Util qw(min); +use Travel::Status::DE::IRIS; +use Travel::Status::DE::DBWagenreihung; + +my $developer_mode = 0; + +sub show_help { + my ($code) = @_; + + say "Usage: db-wagenreihung "; + + exit $code; +} + +sub show_version { + say "db-wagenreihung version ${VERSION}"; + + exit 0; +} + +GetOptions( + 'h|help' => sub { show_help(0) }, + 'devmode' => \$developer_mode, + 'version' => sub { show_version() }, +) or show_help(1); + +if ( @ARGV != 2 ) { + show_help(1); +} + +my ( $station, $train_number ) = @ARGV; + +my $col_first = "\e[38;5;11m"; +my $col_mixed = "\e[38;5;208m"; +my $col_second = "\e[38;5;9m"; +my $col_reset = "\e[0m"; + +my $res = Travel::Status::DE::IRIS->new( + developer_mode => $developer_mode, + station => $station, + with_related => 1 +); + +if ( $res->errstr ) { + say STDERR $res->errstr; + exit 1; +} + +my @trains = grep { $_->train_no eq $train_number } $res->results; + +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, + developer_mode => $developer_mode, + train_number => $train_number, +); + +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 ); + + if ( $section_length % 2 ) { + $spacing_left++; + } + + printf( "|%s%s%s|", + ' ' x $spacing_left, + $section->name, + ' ' x $spacing_right ); +} +print "\n"; + +my @start_percentages = map { $_->{position}{start_percent} } $wr->wagons; +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 ) { + $spacing_left++; + } + + my $wagon_desc = $wagon->number || '?'; + + if ( $wagon->is_locomotive or $wagon->is_powercar ) { + $wagon_desc = '<->'; + } + + my $class_color = ''; + if ( $wagon->class_type == 1 ) { + $class_color = $col_first; + } + elsif ( $wagon->class_type == 2 ) { + $class_color = $col_second; + } + elsif ( $wagon->class_type == 12 ) { + $class_color = $col_mixed; + } + + printf( "%s%s%3s%s%s", + ' ' x $spacing_left, $class_color, $wagon_desc, + $col_reset, ' ' x $spacing_right ); +} +print "\n"; diff --git a/bin/dbwagenreihung b/bin/dbwagenreihung deleted file mode 100755 index 100f4b1..0000000 --- a/bin/dbwagenreihung +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use 5.020; -use utf8; - -our $VERSION = '0.00'; - -use Getopt::Long; -use List::Util qw(min); -use Travel::Status::DE::IRIS; -use Travel::Status::DE::DBWagenreihung; - -my $developer_mode = 0; - -sub show_help { - my ($code) = @_; - - say "Usage: db-wagenreihung "; - - exit $code; -} - -sub show_version { - say "db-wagenreihung version ${VERSION}"; - - exit 0; -} - -GetOptions( - 'h|help' => sub { show_help(0) }, - 'devmode' => \$developer_mode, - 'version' => sub { show_version() }, -) or show_help(1); - -if ( @ARGV != 2 ) { - show_help(1); -} - -my ( $station, $train_number ) = @ARGV; - -my $col_first = "\e[38;5;11m"; -my $col_mixed = "\e[38;5;208m"; -my $col_second = "\e[38;5;9m"; -my $col_reset = "\e[0m"; - -my $res = Travel::Status::DE::IRIS->new( - developer_mode => $developer_mode, - station => $station, - with_related => 1 -); - -if ( $res->errstr ) { - say STDERR $res->errstr; - exit 1; -} - -my @trains = grep { $_->train_no eq $train_number } $res->results; - -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, - developer_mode => $developer_mode, - train_number => $train_number, -); - -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 ); - - if ( $section_length % 2 ) { - $spacing_left++; - } - - printf( "|%s%s%s|", - ' ' x $spacing_left, - $section->name, - ' ' x $spacing_right ); -} -print "\n"; - -my @start_percentages = map { $_->{position}{start_percent} } $wr->wagons; -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 ) { - $spacing_left++; - } - - my $wagon_desc = $wagon->number || '?'; - - if ( $wagon->is_locomotive or $wagon->is_powercar ) { - $wagon_desc = '<->'; - } - - my $class_color = ''; - if ( $wagon->class_type == 1 ) { - $class_color = $col_first; - } - elsif ( $wagon->class_type == 2 ) { - $class_color = $col_second; - } - elsif ( $wagon->class_type == 12 ) { - $class_color = $col_mixed; - } - - printf( "%s%s%3s%s%s", - ' ' x $spacing_left, $class_color, $wagon_desc, - $col_reset, ' ' x $spacing_right ); -} -print "\n"; -- cgit v1.2.3