diff options
Diffstat (limited to 'bin/efa-m')
| -rwxr-xr-x | bin/efa-m | 53 |
1 files changed, 36 insertions, 17 deletions
@@ -4,7 +4,7 @@ use warnings; use 5.010; use utf8; -our $VERSION = '3.09'; +our $VERSION = '3.18'; binmode( STDOUT, ':encoding(utf-8)' ); @@ -16,7 +16,6 @@ use Travel::Status::DE::EFA; my $service = 'VRR'; my $efa_url; -my $efa_encoding; my $use_cache = 1; my $cache; my ( $json_output, $raw_json_output ); @@ -99,12 +98,15 @@ if ($use_cache) { my ( $place, $input, $coord, $stopseq, $stopfinder ); if ( @ARGV == 1 ) { - if ( $ARGV[0] =~ m{ ^ ([^@]*) @ ([^@]*) [(] ([^)]*) [)] (.*) $ }x ) { + if ( $ARGV[0] + =~ m{ ^ ([^@]*) @ ([^@]*) [(] ([^T]*) T ([^)]*) [)] (.*) $ }x ) + { $stopseq = { stateless => $1, stop_id => $2, date => $3, - key => $4 + time => $4, + key => $5 }; } elsif ( $ARGV[0] =~ m{ ^ [?] (?<name> .*) $ }x ) { @@ -156,8 +158,7 @@ elsif ($service) { ); exit 1; } - $efa_encoding = $service_ref->{encoding}; - $efa_url = undef; + $efa_url = undef; } sub new_efa { @@ -168,7 +169,6 @@ sub new_efa { cache => $cache, date => $date, developer_mode => $developer_mode, - efa_encoding => $efa_encoding, full_routes => $full_routes, place => $place, name => $input, @@ -233,7 +233,13 @@ sub format_route { if ( $stop->delay ) { $delay = sprintf( '(%+3d)', $stop->delay ); } - if ( defined $stop->arr and defined $stop->dep ) { + if ( $stop->is_cancelled ) { + $output .= sprintf( + " --:-- %s %s %35s %s\n", + $delay, $occupancy, $stop->full_name, $stop->platform // q{}, + ); + } + elsif ( defined $stop->arr and defined $stop->dep ) { if ( $stop->arr->epoch == $stop->dep->epoch ) { $output .= sprintf( " %5s %s %s %35s %s\n", @@ -347,6 +353,7 @@ sub show_stopseq { ); say q{}; + my $occupancy_len = 0; my $delay_len = 0; my $inner_delay_len = 0; my $max_delay = max map { abs( $_->delay // 0 ) } $trip->route; @@ -354,19 +361,31 @@ sub show_stopseq { $inner_delay_len = length($max_delay) + 1; $delay_len = length( sprintf( '(%+d)', $max_delay ) ) + 1; } + if ( first { $_->occupancy } $trip->route ) { + $occupancy_len = 2; + } + + if ( first { $_->is_cancelled } $trip->route and $delay_len < 3 ) { + $delay_len = 3; + } for my $stop ( $trip->route ) { printf( - "%s → %s%${delay_len}s %s (%s) %s\n", + "%s → %s%${delay_len}s %-${occupancy_len}s%s (%s) %s\n", $stop->arr ? $stop->arr->strftime('%H:%M') : q{ }, $stop->dep ? $stop->dep->strftime('%H:%M') : q{ }, - $stop->delay ? sprintf( " (%+${inner_delay_len}d)", $stop->delay ) - : q{}, + $stop->is_cancelled ? 'XX' + : ( + $stop->delay + ? sprintf( " (%+${inner_delay_len}d)", $stop->delay ) + : q{} + ), + $stop->occupancy ? format_occupancy( $stop->occupancy ) : q{}, $stop->full_name, - $stop->niveau, - $stop->platform + $stop->niveau // q{?}, + $stop->platform // q{} ); } } @@ -571,14 +590,14 @@ if ( my $err = $efa->errstr ) { if ($json_output) { if ($stopseq) { - say JSON->new->convert_blessed->encode( $efa->result ); + say JSON->new->canonical->convert_blessed->encode( $efa->result ); } else { - say JSON->new->convert_blessed->encode( [ $efa->results ] ); + say JSON->new->canonical->convert_blessed->encode( [ $efa->results ] ); } } elsif ($raw_json_output) { - say JSON->new->convert_blessed->encode( $efa->{response} ); + say JSON->new->canonical->convert_blessed->encode( $efa->{response} ); } elsif ($coord) { show_coord(); @@ -614,7 +633,7 @@ B<efa-m> [B<-s> I<service>] I<tripid> =head1 VERSION -version 3.09 +version 3.18 =head1 DESCRIPTION |
