summaryrefslogtreecommitdiff
path: root/lib/Travelynx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travelynx')
-rw-r--r--lib/Travelynx/Command/work.pm12
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm7
-rw-r--r--lib/Travelynx/Helper/IRIS.pm71
3 files changed, 87 insertions, 3 deletions
diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm
index 727a694..9c870d8 100644
--- a/lib/Travelynx/Command/work.pm
+++ b/lib/Travelynx/Command/work.pm
@@ -35,7 +35,11 @@ sub run {
eval {
if ( $now->epoch - $entry->{real_dep_ts} < 900 ) {
- my $status = $self->app->get_departures( $dep, 30, 30 );
+ my $status = $self->app->iris->get_departures(
+ station => $dep,
+ lookbehind => 30,
+ lookahead => 30
+ );
if ( $status->{errstr} ) {
die("get_departures($dep): $status->{errstr}\n");
}
@@ -123,7 +127,11 @@ sub run {
or $now->epoch - $entry->{real_arr_ts} < 600 )
)
{
- my $status = $self->app->get_departures( $arr, 20, 220 );
+ my $status = $self->app->iris->get_departures(
+ station => $arr,
+ lookbehind => 20,
+ lookahead => 220
+ );
if ( $status->{errstr} ) {
die("get_departures($arr): $status->{errstr}\n");
}
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index 05bbccd..e33009f 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -423,7 +423,12 @@ sub station {
my $station = $self->stash('station');
my $train = $self->param('train');
- my $status = $self->get_departures( $station, 120, 30, 1 );
+ my $status = $self->iris->get_departures(
+ station => $station,
+ lookbehind => 120,
+ lookahead => 30,
+ with_related => 1
+ );
if ( $status->{errstr} ) {
$self->render(
diff --git a/lib/Travelynx/Helper/IRIS.pm b/lib/Travelynx/Helper/IRIS.pm
new file mode 100644
index 0000000..3b98a51
--- /dev/null
+++ b/lib/Travelynx/Helper/IRIS.pm
@@ -0,0 +1,71 @@
+package Travelynx::Helper::IRIS;
+
+use strict;
+use warnings;
+use 5.020;
+
+use Travel::Status::DE::IRIS;
+
+sub new {
+ my ( $class, %opt ) = @_;
+
+ return bless( \%opt, $class );
+}
+
+sub get_departures {
+ my ( $self, %opt ) = @_;
+ my $station = $opt{station};
+ my $lookbehind = $opt{lookbehind} // 180;
+ my $lookahead = $opt{lookahead} // 30;
+ my $with_related = $opt{with_related} // 0;
+
+ my @station_matches
+ = Travel::Status::DE::IRIS::Stations::get_station($station);
+
+ if ( @station_matches == 1 ) {
+ $station = $station_matches[0][0];
+ my $status = Travel::Status::DE::IRIS->new(
+ station => $station,
+ main_cache => $self->{main_cache},
+ realtime_cache => $self->{realtime_cache},
+ keep_transfers => 1,
+ lookbehind => 20,
+ datetime => DateTime->now( time_zone => 'Europe/Berlin' )
+ ->subtract( minutes => $lookbehind ),
+ lookahead => $lookbehind + $lookahead,
+ lwp_options => {
+ timeout => 10,
+ agent => 'travelynx/'
+ . $self->{version}
+ . ' +https://travelynx.de',
+ },
+ with_related => $with_related,
+ );
+ return {
+ results => [ $status->results ],
+ errstr => $status->errstr,
+ station_ds100 =>
+ ( $status->station ? $status->station->{ds100} : undef ),
+ station_eva =>
+ ( $status->station ? $status->station->{uic} : undef ),
+ station_name =>
+ ( $status->station ? $status->station->{name} : undef ),
+ related_stations => [ $status->related_stations ],
+ };
+ }
+ elsif ( @station_matches > 1 ) {
+ return {
+ results => [],
+ errstr => 'Mehrdeutiger Stationsname. Mögliche Eingaben: '
+ . join( q{, }, map { $_->[1] } @station_matches ),
+ };
+ }
+ else {
+ return {
+ results => [],
+ errstr => 'Unbekannte Station',
+ };
+ }
+}
+
+1;