summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/EFA.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travel/Status/DE/EFA.pm')
-rw-r--r--lib/Travel/Status/DE/EFA.pm204
1 files changed, 99 insertions, 105 deletions
diff --git a/lib/Travel/Status/DE/EFA.pm b/lib/Travel/Status/DE/EFA.pm
index e1c8edf..56a870d 100644
--- a/lib/Travel/Status/DE/EFA.pm
+++ b/lib/Travel/Status/DE/EFA.pm
@@ -5,11 +5,10 @@ use warnings;
use 5.010;
use utf8;
-no if $] >= 5.018, warnings => 'experimental::smartmatch';
-
-our $VERSION = '1.19';
+our $VERSION = '2.00';
use Carp qw(confess cluck);
+use DateTime;
use Encode qw(encode);
use Travel::Status::DE::EFA::Line;
use Travel::Status::DE::EFA::Result;
@@ -34,7 +33,9 @@ sub new {
if ( not( $opt{name} ) ) {
confess('You must specify a name');
}
- if ( $opt{type} and not( $opt{type} ~~ [qw[stop stopID address poi]] ) ) {
+ if ( $opt{type}
+ and not( $opt{type} =~ m{ ^ (?: stop stopID address poi ) $ }x ) )
+ {
confess('type must be stop, stopID, address, or poi');
}
@@ -194,33 +195,6 @@ sub place_candidates {
return;
}
-sub sprintf_date {
- my ($e) = @_;
-
- if ( $e->getAttribute('day') == -1 ) {
- return;
- }
-
- return sprintf( '%02d.%02d.%d',
- $e->getAttribute('day'),
- $e->getAttribute('month'),
- $e->getAttribute('year'),
- );
-}
-
-sub sprintf_time {
- my ($e) = @_;
-
- if ( $e->getAttribute('minute') == -1 ) {
- return;
- }
-
- return sprintf( '%02d:%02d',
- $e->getAttribute('hour'),
- $e->getAttribute('minute'),
- );
-}
-
sub check_for_ambiguous {
my ($self) = @_;
@@ -332,7 +306,7 @@ sub lines {
my $type = $e_info->getAttribute('name');
my $mot = $e->getAttribute('motType');
my $route = ( $e_route ? $e_route->textContent : undef );
- my $operator = ( $e_oper ? $e_oper->textContent : undef );
+ my $operator = ( $e_oper ? $e_oper->textContent : undef );
my $identifier = $e->getAttribute('stateless');
push(
@@ -368,17 +342,45 @@ sub parse_route {
my @dates = $e->findnodes($xp_routepoint_date);
my @times = $e->findnodes($xp_routepoint_time);
+ my ( $arr, $dep );
+
# note that the first stop has an arrival node with an invalid
# timestamp and the terminal stop has a departure node with an
- # invalid timestamp. sprintf_{date,time} return undef in these
- # cases.
+ # invalid timestamp.
+
+ if ( $dates[0] and $times[0] and $dates[0]->getAttribute('day') != -1 )
+ {
+ $arr = DateTime->new(
+ year => $dates[0]->getAttribute('year'),
+ month => $dates[0]->getAttribute('month'),
+ day => $dates[0]->getAttribute('day'),
+ hour => $times[0]->getAttribute('hour'),
+ minute => $times[0]->getAttribute('minute'),
+ second => $times[0]->getAttribute('second') // 0,
+ time_zone => 'Europe/Berlin'
+ );
+ }
+
+ if ( $dates[-1]
+ and $times[-1]
+ and $dates[-1]->getAttribute('day') != -1 )
+ {
+ $dep = DateTime->new(
+ year => $dates[-1]->getAttribute('year'),
+ month => $dates[-1]->getAttribute('month'),
+ day => $dates[-1]->getAttribute('day'),
+ hour => $times[-1]->getAttribute('hour'),
+ minute => $times[-1]->getAttribute('minute'),
+ second => $times[-1]->getAttribute('second') // 0,
+ time_zone => 'Europe/Berlin'
+ );
+ }
+
push(
@ret,
Travel::Status::DE::EFA::Stop->new(
- arr_date => sprintf_date( $dates[0] ),
- arr_time => sprintf_time( $times[0] ),
- dep_date => sprintf_date( $dates[-1] ),
- dep_time => sprintf_time( $times[-1] ),
+ arr => $arr,
+ dep => $dep,
name => $e->getAttribute('name'),
name_suf => $e->getAttribute('nameWO'),
platform => $e->getAttribute('platformName'),
@@ -432,17 +434,39 @@ sub results {
next;
}
- my $date = sprintf_date($e_date);
- my $time = sprintf_time($e_time);
+ my ( $sched_dt, $real_dt );
+
+ if ( $e_date and $e_time and $e_date->getAttribute('day') != -1 ) {
+ $sched_dt = DateTime->new(
+ year => $e_date->getAttribute('year'),
+ month => $e_date->getAttribute('month'),
+ day => $e_date->getAttribute('day'),
+ hour => $e_time->getAttribute('hour'),
+ minute => $e_time->getAttribute('minute'),
+ second => $e_time->getAttribute('second') // 0,
+ time_zone => 'Europe/Berlin'
+ );
+ }
- my $rdate = $e_rdate ? sprintf_date($e_rdate) : $date;
- my $rtime = $e_rtime ? sprintf_time($e_rtime) : $time;
+ if ( $e_rdate and $e_rtime and $e_rdate->getAttribute('day') != -1 ) {
+ $real_dt = DateTime->new(
+ year => $e_rdate->getAttribute('year'),
+ month => $e_rdate->getAttribute('month'),
+ day => $e_rdate->getAttribute('day'),
+ hour => $e_rtime->getAttribute('hour'),
+ minute => $e_rtime->getAttribute('minute'),
+ second => $e_rtime->getAttribute('second') // 0,
+ time_zone => 'Europe/Berlin'
+ );
+ }
my $platform = $e->getAttribute('platform');
my $platform_name = $e->getAttribute('platformName');
my $countdown = $e->getAttribute('countdown');
my $occupancy = $e->getAttribute('occupancy');
my $line = $e_line->getAttribute('number');
+ my $train_type = $e_line->getAttribute('trainType');
+ my $train_name = $e_line->getAttribute('trainName');
my $train_no = $e_line->getAttribute('trainNum');
my $dest = $e_line->getAttribute('direction');
my $info = $e_info->textContent;
@@ -494,26 +518,26 @@ sub results {
push(
@results,
Travel::Status::DE::EFA::Result->new(
- date => $rdate,
- time => $rtime,
- platform => $platform,
- platform_db => $platform_is_db,
- platform_name => $platform_name,
- key => $key,
- lineref => $line_obj[0] // undef,
- line => $line,
- train_no => $train_no,
- destination => $dest,
- occupancy => $occupancy,
- countdown => $countdown,
- info => $info,
- delay => $delay,
- sched_date => $date,
- sched_time => $time,
- type => $type,
- mot => $mot,
- prev_route => \@prev_route,
- next_route => \@next_route,
+ rt_datetime => $real_dt,
+ platform => $platform,
+ platform_db => $platform_is_db,
+ platform_name => $platform_name,
+ key => $key,
+ lineref => $line_obj[0] // undef,
+ line => $line,
+ train_type => $train_type,
+ train_name => $train_name,
+ train_no => $train_no,
+ destination => $dest,
+ occupancy => $occupancy,
+ countdown => $countdown,
+ info => $info,
+ delay => $delay,
+ sched_datetime => $sched_dt,
+ type => $type,
+ mot => $mot,
+ prev_route => \@prev_route,
+ next_route => \@next_route,
)
);
}
@@ -563,39 +587,11 @@ sub get_efa_urls {
name => 'Nahverkehrsgesellschaft Baden-Württemberg',
shortname => 'NVBW',
},
-
- # HTTPS not supported
- {
- url => 'http://efa.svv-info.at/sbs/XSLT_DM_REQUEST',
- name => 'Salzburger Verkehrsverbund',
- shortname => 'SVV',
- },
-
- # HTTPS: invalid certificate
- {
- url => 'http://www.travelineeastmidlands.co.uk/em/XSLT_DM_REQUEST',
- name => 'Traveline East Midlands',
- shortname => 'TLEM',
- },
{
url => 'https://efa.vagfr.de/vagfr3/XSLT_DM_REQUEST',
name => 'Freiburger Verkehrs AG',
shortname => 'VAG',
},
-
- # HTTPS: unsupported protocol
- {
- url => 'http://mobil.vbl.ch/vblmobil/XML_DM_REQUEST',
- name => 'Verkehrsbetriebe Luzern',
- shortname => 'VBL',
- },
-
- # HTTPS not supported
- {
- url => 'http://fahrplan.verbundlinie.at/stv/XSLT_DM_REQUEST',
- name => 'Verkehrsverbund Steiermark',
- shortname => 'Verbundlinie',
- },
{
url => 'https://efa.vgn.de/vgnExt_oeffi/XML_DM_REQUEST',
name => 'Verkehrsverbund Grossraum Nuernberg',
@@ -609,15 +605,7 @@ sub get_efa_urls {
shortname => 'VMV',
},
{
- url => 'https://efa.vor.at/wvb/XSLT_DM_REQUEST',
- name => 'Verkehrsverbund Ost-Region',
- shortname => 'VOR',
- encoding => 'iso-8859-15',
- },
-
- # HTTPS not supported
- {
- url => 'http://fahrplanauskunft.vrn.de/vrn/XML_DM_REQUEST',
+ url => 'https://www.vrn.de/mngvrn//XML_DM_REQUEST',
name => 'Verkehrsverbund Rhein-Neckar',
shortname => 'VRN',
},
@@ -631,10 +619,13 @@ sub get_efa_urls {
name => 'Verkehrsverbund Rhein-Ruhr (alternative)',
shortname => 'VRR2',
},
-
- # HTTPS not supported
{
- url => 'http://efa.vvo-online.de:8080/dvb/XSLT_DM_REQUEST',
+ url => 'https://efa.vrr.de/rbgstd3/XML_DM_REQUEST',
+ name => 'Verkehrsverbund Rhein-Ruhr (alternative alternative)',
+ shortname => 'VRR3',
+ },
+ {
+ url => 'https://efa.vvo-online.de/VMSSL3/XSLT_DM_REQUEST',
name => 'Verkehrsverbund Oberelbe',
shortname => 'VVO',
},
@@ -667,13 +658,14 @@ Travel::Status::DE::EFA - unofficial EFA departure monitor
for my $d ($status->results) {
printf(
"%s %-8s %-5s %s\n",
- $d->time, $d->platform_name, $d->line, $d->destination
+ $d->datetime->strftime('%H:%M'),
+ $d->platform_name, $d->line, $d->destination
);
}
=head1 VERSION
-version 1.19
+version 2.00
=head1 DESCRIPTION
@@ -799,6 +791,8 @@ None.
=item * Class::Accessor(3pm)
+=item * DateTime(3pm)
+
=item * LWP::UserAgent(3pm)
=item * XML::LibXML(3pm)
@@ -815,7 +809,7 @@ efa-m(1), Travel::Status::DE::EFA::Result(3pm).
=head1 AUTHOR
-Copyright (C) 2011-2015 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt>
+Copyright (C) 2011-2023 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>
=head1 LICENSE