Loading examples/traintrack +72 −59 Original line number Diff line number Diff line Loading @@ -64,7 +64,8 @@ sub get_train_or_undef { say STDERR "Request warning at ${station}: ${warn}"; } my @res = grep { $_->type eq $train_type and $_->train_no eq $train_no } $status->results; my @res = grep { $_->type eq $train_type and $_->train_no eq $train_no } $status->results; if ( @res == 1 ) { return $res[0]; Loading Loading @@ -137,7 +138,8 @@ my $initial_train = get_train_or_undef($dest_station); if ( not defined $initial_train ) { say STDERR "Did not find $train_type $train_no at $dest_station\n"; say STDERR "Note that its arrival must not be more than 5 hours in the future\n"; say STDERR "Note that its arrival must not be more than 5 hours in the future\n"; } my @stations = ( $initial_train->route_pre, $dest_station ); Loading Loading @@ -185,9 +187,15 @@ while (1) { } else { my $epoch = $status{$station}{epoch}; my @messages = grep { $_->[0]->epoch > $prev_epoch and $_->[0]->epoch <= $epoch } @all_messages; my @messages = grep { $_->[0]->epoch > $prev_epoch and $_->[0]->epoch <= $epoch } @all_messages; for my $message (@messages) { printf("%30s %5s %s\n", q{}, $message->[0]->strftime('%H:%M'), $message->[1]); printf( "%30s %5s %s\n", q{}, $message->[0]->strftime('%H:%M'), $message->[1] ); } if (@messages) { print "\n"; Loading @@ -197,14 +205,19 @@ while (1) { printf( "%30s %5s\n\n", '>' x 15, $now->strftime('%H:%M') ); } printf("%30s %5s → %5s %s\n", $station, format_datetime($status{$station}{sched_arrival}), printf( "%30s %5s → %5s %s\n", $station, format_datetime( $status{$station}{sched_arrival} ), format_datetime( $status{$station}{sched_departure} ), format_delay( $status{$station}{delay} ), ); if ($status{$station}{arrival_delay} or $status{$station}{departure_delay}) { printf("%30s %5s → %5s\n", if ( $status{$station}{arrival_delay} or $status{$station}{departure_delay} ) { printf( "%30s %5s → %5s\n", q{}, format_datetime( $status{$station}{rt_arrival} ), format_datetime( $status{$station}{rt_departure} ), Loading Loading
examples/traintrack +72 −59 Original line number Diff line number Diff line Loading @@ -64,7 +64,8 @@ sub get_train_or_undef { say STDERR "Request warning at ${station}: ${warn}"; } my @res = grep { $_->type eq $train_type and $_->train_no eq $train_no } $status->results; my @res = grep { $_->type eq $train_type and $_->train_no eq $train_no } $status->results; if ( @res == 1 ) { return $res[0]; Loading Loading @@ -137,7 +138,8 @@ my $initial_train = get_train_or_undef($dest_station); if ( not defined $initial_train ) { say STDERR "Did not find $train_type $train_no at $dest_station\n"; say STDERR "Note that its arrival must not be more than 5 hours in the future\n"; say STDERR "Note that its arrival must not be more than 5 hours in the future\n"; } my @stations = ( $initial_train->route_pre, $dest_station ); Loading Loading @@ -185,9 +187,15 @@ while (1) { } else { my $epoch = $status{$station}{epoch}; my @messages = grep { $_->[0]->epoch > $prev_epoch and $_->[0]->epoch <= $epoch } @all_messages; my @messages = grep { $_->[0]->epoch > $prev_epoch and $_->[0]->epoch <= $epoch } @all_messages; for my $message (@messages) { printf("%30s %5s %s\n", q{}, $message->[0]->strftime('%H:%M'), $message->[1]); printf( "%30s %5s %s\n", q{}, $message->[0]->strftime('%H:%M'), $message->[1] ); } if (@messages) { print "\n"; Loading @@ -197,14 +205,19 @@ while (1) { printf( "%30s %5s\n\n", '>' x 15, $now->strftime('%H:%M') ); } printf("%30s %5s → %5s %s\n", $station, format_datetime($status{$station}{sched_arrival}), printf( "%30s %5s → %5s %s\n", $station, format_datetime( $status{$station}{sched_arrival} ), format_datetime( $status{$station}{sched_departure} ), format_delay( $status{$station}{delay} ), ); if ($status{$station}{arrival_delay} or $status{$station}{departure_delay}) { printf("%30s %5s → %5s\n", if ( $status{$station}{arrival_delay} or $status{$station}{departure_delay} ) { printf( "%30s %5s → %5s\n", q{}, format_datetime( $status{$station}{rt_arrival} ), format_datetime( $status{$station}{rt_departure} ), Loading