From d30a3aff786d3ce655cc043feda7b0462f3ab998 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 25 Mar 2021 21:48:02 +0100 Subject: make "place" optional --- bin/efa-m | 23 ++++++++++++++++------- lib/Travel/Status/DE/EFA.pm | 17 ++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/bin/efa-m b/bin/efa-m index e30a6fb..7cda15e 100755 --- a/bin/efa-m +++ b/bin/efa-m @@ -56,7 +56,7 @@ if ($list_services) { show_services(); } -if ( @ARGV != 2 ) { +if ( @ARGV < 1 or @ARGV > 2 ) { show_help(1); } @@ -66,7 +66,14 @@ if ( @ARGV != 2 ) { @grep_mots = split( qr{,}, join( q{,}, @grep_mots ) ); @grep_platforms = split( qr{,}, join( q{,}, @grep_platforms ) ); -my ( $place, $input ) = @ARGV; +my ( $place, $input ); + +if ( @ARGV == 1 ) { + $input = $ARGV[0]; +} +else { + ( $place, $input ) = @ARGV; +} if ( $input =~ s{ ^ (? address|poi|stop) : }{}x ) { $input_type = $+{type}; @@ -121,7 +128,7 @@ sub new_efa_by_url { sub show_help { my ($code) = @_; - print "Usage: efa-m [-d ] [-t ] \n" + print "Usage: efa-m [-d ] [-t ] [place] \n" . "See also: man efa-m\n"; exit $code; @@ -385,7 +392,7 @@ efa-m - Unofficial interface to the efa.vrr.de departure monitor B [B<-Lr>] [B<-d> I] [B<-t> I] [B<-l> I] [B<-p> I] [B<-u> I] -I [IB<:>]I +[I] [IB<:>]I =head1 VERSION @@ -393,9 +400,11 @@ version 1.17 =head1 DESCRIPTION -B lists scheduled tram, bus and train departures at the location I -in I. Realtime data (i.e. delays) is included if available, it's -visible in the output as a "+x" remark (meaning a delay of x minutes). +B lists scheduled tram, bus and train departures at the location I. +If I is specified, I refers to a location within I. Otherwise, +I must be self-contained. I.e., both C<< efa Essen Hbf >> and +C<< efa "Essen Hbf" >> are valid. Note, however, than C<< efa E Hbf >> works, +but C<< efa "E Hbf" >> does not. By default, I refers to a stop, this can be changed by specifying I. Supported types are B
and B (point of interest). diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm index ca18273..a0a7c41 100644 --- a/lib/Travel/Status/DE/EFA.pm +++ b/lib/Travel/Status/DE/EFA.pm @@ -31,8 +31,8 @@ sub new { my @time = @now[ 2, 1 ]; my @date = ( $now[3], $now[4] + 1, $now[5] + 1900 ); - if ( not( $opt{place} and $opt{name} ) ) { - confess('You need to specify a place and a name'); + if ( not( $opt{name} ) ) { + confess('You must specify a name'); } if ( $opt{type} and not( $opt{type} ~~ [qw[stop address poi]] ) ) { confess('type must be stop, address or poi'); @@ -93,9 +93,6 @@ sub new { nameState_dm => 'empty', name_dm => encode( 'UTF-8', $opt{name} ), outputFormat => 'XML', - placeInfo_dm => 'invalid', - placeState_dm => 'empty', - place_dm => encode( 'UTF-8', $opt{place} ), ptOptionsActive => '1', requestID => '0', reset => 'neue Anfrage', @@ -109,6 +106,12 @@ sub new { developer_mode => $opt{developer_mode}, }; + if ( $opt{place} ) { + $self->{post}{placeInfo_dm} = 'invalid'; + $self->{post}{placeState_dm} = 'empty'; + $self->{post}{place_dm} = encode( 'UTF-8', $opt{place} ); + } + if ( $opt{full_routes} ) { $self->{post}->{depType} = 'stopEvents'; $self->{post}->{includeCompleteStopSeq} = 1; @@ -656,7 +659,7 @@ Travel::Status::DE::EFA - unofficial EFA departure monitor my $status = Travel::Status::DE::EFA->new( efa_url => 'https://efa.vrr.de/vrr/XSLT_DM_REQUEST', - place => 'Essen', name => 'Helenenstr' + name => 'Essen Helenenstr' ); for my $d ($status->results) { @@ -684,7 +687,7 @@ It reports all upcoming tram/bus/train departures at a given place. =item my $status = Travel::Status::DE::EFA->new(I<%opt>) Requests the departures as specified by I and returns a new -Travel::Status::DE::EFA object. B, B and B are +Travel::Status::DE::EFA object. B and B are mandatory. Dies if the wrong I were passed. Arguments: -- cgit v1.2.3