diff options
-rwxr-xr-x | bin/efa-m | 17 | ||||
-rw-r--r-- | lib/Travel/Status/DE/EFA/Departure.pm | 13 | ||||
-rw-r--r-- | lib/Travel/Status/DE/EFA/Stop.pm | 10 | ||||
-rw-r--r-- | lib/Travel/Status/DE/EFA/Trip.pm | 6 |
4 files changed, 40 insertions, 6 deletions
@@ -10,7 +10,8 @@ binmode( STDOUT, ':encoding(utf-8)' ); use Encode qw(decode); use Getopt::Long qw(:config no_ignore_case bundling); -use List::Util qw(first max none); +use JSON; +use List::Util qw(first max none); use Travel::Status::DE::EFA; my $service = 'VRR'; @@ -18,6 +19,7 @@ my $efa_url; my $efa_encoding; my $use_cache = 1; my $cache; +my $json_output; my ( $date, $time, $input_type, $list_lines, $offset, $relative_times ); my ( $full_routes, $filter_via, $show_jid ); my ( $timeout, $developer_mode ); @@ -57,8 +59,9 @@ GetOptions( 'v|via=s' => \$filter_via, 'V|track-via=s' => \$filter_via, 'cache!' => \$use_cache, - 'version' => \&show_version, + 'json' => \$json_output, 'devmode' => \$developer_mode, + 'version' => \&show_version, ) or show_help(1); @@ -497,7 +500,15 @@ if ( my $err = $efa->errstr ) { exit 2; } -if ($stopseq) { +if ($json_output) { + if ($stopseq) { + say JSON->new->convert_blessed->encode( $efa->result ); + } + else { + say JSON->new->convert_blessed->encode( [ $efa->results ] ); + } +} +elsif ($stopseq) { show_stopseq(); } elsif ($list_lines) { diff --git a/lib/Travel/Status/DE/EFA/Departure.pm b/lib/Travel/Status/DE/EFA/Departure.pm index 703b29c..3ad68a5 100644 --- a/lib/Travel/Status/DE/EFA/Departure.pm +++ b/lib/Travel/Status/DE/EFA/Departure.pm @@ -246,7 +246,18 @@ sub route_interesting { sub TO_JSON { my ($self) = @_; - return { %{$self} }; + my $ret = { %{$self} }; + + delete $ret->{strp_stopseq}; + delete $ret->{strp_stopseq_s}; + + for my $k (qw(datetime rt_datetime sched_datetime)) { + if ( $ret->{$k} ) { + $ret->{$k} = $ret->{$k}->epoch; + } + } + + return $ret; } 1; diff --git a/lib/Travel/Status/DE/EFA/Stop.pm b/lib/Travel/Status/DE/EFA/Stop.pm index b97cd18..4d7fbe9 100644 --- a/lib/Travel/Status/DE/EFA/Stop.pm +++ b/lib/Travel/Status/DE/EFA/Stop.pm @@ -30,7 +30,15 @@ sub new { sub TO_JSON { my ($self) = @_; - return { %{$self} }; + my $ret = { %{$self} }; + + for my $k (qw(sched_arr rt_arr arr sched_dep rt_dep dep)) { + if ( $ret->{$k} ) { + $ret->{$k} = $ret->{$k}->epoch; + } + } + + return $ret; } 1; diff --git a/lib/Travel/Status/DE/EFA/Trip.pm b/lib/Travel/Status/DE/EFA/Trip.pm index 6c404a1..b1e3437 100644 --- a/lib/Travel/Status/DE/EFA/Trip.pm +++ b/lib/Travel/Status/DE/EFA/Trip.pm @@ -106,7 +106,11 @@ sub route { sub TO_JSON { my ($self) = @_; - return { %{$self} }; + my $ret = { %{$self} }; + + delete $ret->{strptime_obj}; + + return $ret; } 1; |