Commit 9590fab2 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Remove support for RIS/HAFAS backend

parent 165d7493
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -90,7 +90,6 @@ db-infoscreen respects the following environment variables:
| DBFAKEDISPLAY\_LISTEN | `http://*:8092` | IP and Port for web service |
| DBFAKEDISPLAY\_STATS | _None_ | File in which the total count of backend API requests (excluding those answered from cache) is written |
| DBFAKEDISPLAY\_HAFAS\_API | `https://v5.db.transport.rest` | hafas-rest-api endpoint |
| DBFAKEDISPLAY\_HAFAS\_CACHE | `/tmp/dbf-hafas` | Directory for HAFAS cache |
| DBFAKEDISPLAY\_IRIS\_CACHE | `/tmp/dbf-iris-mian` | Directory for IRIS schedule cache |
| DBFAKEDISPLAY\_IRISRT\_CACHE | `/tmp/dbf-iris-realtime` | Directory for IRIS realtime cache |
| DBFAKEDISPLAY\_WORKERS | 2 | Number of worker processes (i.e., maximum amount of concurrent requests) |
+0 −1
Original line number Diff line number Diff line
@@ -10,6 +10,5 @@ requires 'LWP::UserAgent';
requires 'LWP::Protocol::https';
requires 'Mojolicious';
requires 'Travel::Status::DE::DBWagenreihung', '0.06';
requires 'Travel::Status::DE::DeutscheBahn', '< 3.00';
requires 'Travel::Status::DE::IRIS';
requires 'XML::LibXML';
+0 −25
Original line number Diff line number Diff line
@@ -1915,31 +1915,6 @@ DISTRIBUTIONS
      Test::Pod 0
      Travel::Status::DE::IRIS 1.2
      perl v5.20.0
  Travel-Status-DE-DeutscheBahn-2.05
    pathname: D/DE/DERF/Travel-Status-DE-DeutscheBahn-2.05.tar.gz
    provides:
      Travel::Status::DE::DeutscheBahn 2.05
      Travel::Status::DE::HAFAS 2.05
      Travel::Status::DE::HAFAS::Result 2.05
      Travel::Status::DE::HAFAS::StopFinder 2.05
    requirements:
      Carp 0
      Class::Accessor 0.16
      DateTime 0
      DateTime::Format::Strptime 0
      Getopt::Long 0
      JSON 0
      LWP::Protocol::https 0
      LWP::UserAgent 0
      List::MoreUtils 0
      List::Util 0
      Module::Build 0.4
      POSIX 0
      Test::Compile 0
      Test::More 0
      Test::Pod 0
      XML::LibXML 1.70
      perl v5.14.0
  Travel-Status-DE-IRIS-1.54
    pathname: D/DE/DERF/Travel-Status-DE-IRIS-1.54.tar.gz
    provides:
+0 −20
Original line number Diff line number Diff line
@@ -12,20 +12,12 @@ use DBInfoscreen::Helper::Marudor;
use DBInfoscreen::Helper::Wagonorder;
use File::Slurp qw(read_file);
use JSON;
use Travel::Status::DE::HAFAS;
use Travel::Status::DE::HAFAS::StopFinder;
use Travel::Status::DE::IRIS::Stations;

use utf8;

no if $] >= 5.018, warnings => 'experimental::smartmatch';

my %default = (
	backend => 'iris',
	mode    => 'app',
	admode  => 'deparr',
);

sub startup {
	my ($self) = @_;

@@ -67,18 +59,6 @@ sub startup {
		}
	);

	$self->attr(
		cache_hafas => sub {
			my ($self) = @_;
			return Cache::File->new(
				cache_root => $ENV{DBFAKEDISPLAY_HAFAS_CACHE}
				  // '/tmp/dbf-hafas',
				default_expires => '180 seconds',
				lock_level      => Cache::File::LOCK_LOCAL(),
			);
		}
	);

	$self->attr(
		cache_iris_main => sub {
			my ($self) = @_;
+88 −222
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@ use List::Util qw(max uniq);
use List::MoreUtils qw();
use Mojo::JSON qw(decode_json);
use Mojo::Promise;
use Travel::Status::DE::HAFAS;
use Travel::Status::DE::IRIS;
use Travel::Status::DE::IRIS::Stations;
use XML::LibXML;
@@ -24,35 +23,13 @@ use utf8;
no if $] >= 5.018, warnings => 'experimental::smartmatch';

my %default = (
	backend => 'iris',
	mode   => 'app',
	admode => 'deparr',
);

sub handle_no_results {
	my ( $self, $backend, $station, $errstr ) = @_;
	my ( $self, $station, $errstr ) = @_;

	if ( $backend eq 'ris' ) {
		my $db_service = Travel::Status::DE::HAFAS::get_service('DB');
		my $sf         = Travel::Status::DE::HAFAS::StopFinder->new(
			url   => $db_service->{stopfinder},
			input => $station,
		);
		my @candidates
		  = map { [ $_->{name}, $_->{id} ] } $sf->results;
		if ( @candidates > 1
			or ( @candidates == 1 and $candidates[0][1] ne $station ) )
		{
			$self->render(
				'landingpage',
				stationlist => \@candidates,
				hide_opts   => 0,
				status      => 300,
			);
			return;
		}
	}
	if ( $backend eq 'iris' ) {
	my @candidates = map { [ $_->[1], $_->[0] ] }
	  Travel::Status::DE::IRIS::Stations::get_station($station);
	if ( @candidates > 1
@@ -66,7 +43,6 @@ sub handle_no_results {
		);
		return;
	}
	}
	$self->render(
		'landingpage',
		error     => ( $errstr // "Got no results for '$station'" ),
@@ -76,7 +52,7 @@ sub handle_no_results {
}

sub handle_no_results_json {
	my ( $self, $backend, $station, $errstr, $api_version ) = @_;
	my ( $self, $station, $errstr, $api_version ) = @_;

	my $callback = $self->param('callback');

@@ -134,22 +110,11 @@ sub handle_no_results_json {
sub result_is_train {
	my ( $result, $train ) = @_;

	if ( $result->can('train_id') ) {

		# IRIS
	if ( $train eq $result->type . ' ' . $result->train_no ) {
		return 1;
	}
	return 0;
}
	else {
		# HAFAS
		if ( $train eq $result->type . ' ' . $result->train ) {
			return 1;
		}
		return 0;
	}
}

sub result_has_line {
	my ( $result, @lines ) = @_;
@@ -222,7 +187,7 @@ sub log_api_access {
}

sub get_results_for {
	my ( $backend, $station, %opt ) = @_;
	my ( $station, %opt ) = @_;
	my $data;

	# Cache::File has UTF-8 problems, so strip it (and any other potentially
@@ -230,8 +195,6 @@ sub get_results_for {
	my $cache_str = $station;
	$cache_str =~ tr{[0-9a-zA-Z -]}{}cd;

	if ( $backend eq 'iris' ) {

	if ( $ENV{DBFAKEDISPLAY_STATS} ) {
		log_api_access();
	}
@@ -274,35 +237,6 @@ sub get_results_for {
			errstr  => 'Unknown station name',
		};
	}
	}
	elsif ( $backend eq 'ris' ) {
		$data = $opt{cache_hafas}->thaw($cache_str);
		if ( not $data ) {
			if ( $ENV{DBFAKEDISPLAY_STATS} ) {
				log_api_access();
			}
			my $status = Travel::Status::DE::HAFAS->new(
				station       => $station,
				excluded_mots => [qw[bus ferry ondemand tram u]],
				lwp_options   => {
					timeout => 10,
					agent   => 'dbf.finalrewind.org/2'
				},
				%opt
			);
			$data = {
				results => [ $status->results ],
				errstr  => $status->errstr,
			};
			$opt{cache_hafas}->freeze( $cache_str, $data );
		}
	}
	else {
		$data = {
			results => [],
			errstr  => "Backend '$backend' not supported",
		};
	}

	return $data;
}
@@ -312,18 +246,13 @@ sub handle_request {
	my $station = $self->stash('station');

	my $template     = $self->param('mode') // 'app';
	my $backend  = $self->param('backend') // 'iris';
	my $with_related = !$self->param('no_related');
	my %opt          = (
		cache_hafas     => $self->app->cache_hafas,
		cache_iris_main => $self->app->cache_iris_main,
		cache_iris_rt   => $self->app->cache_iris_rt,
	);

	my $api_version
	  = $backend eq 'iris'
	  ? $Travel::Status::DE::IRIS::VERSION
	  : $Travel::Status::DE::HAFAS::VERSION;
	my $api_version = $Travel::Status::DE::IRIS::VERSION;

	$self->stash( departures => [] );
	$self->stash( title      => 'DBF' );
@@ -372,7 +301,6 @@ sub handle_request {
	$self->param( input => $station );

	if ( $template eq 'json' ) {
		$backend = 'iris';
		$opt{lookahead} = 120;
	}

@@ -389,17 +317,16 @@ sub handle_request {
		$opt{lookahead} = 200;
	}

	my $data   = get_results_for( $backend, $station, %opt );
	my $data   = get_results_for( $station, %opt );
	my $errstr = $data->{errstr};

	if ( not @{ $data->{results} } and $template eq 'json' ) {
		$self->handle_no_results_json( $backend, $station, $errstr,
			$api_version );
		$self->handle_no_results_json( $station, $errstr, $api_version );
		return;
	}

	if ( not @{ $data->{results} } ) {
		$self->handle_no_results( $backend, $station, $errstr );
		$self->handle_no_results( $station, $errstr );
		return;
	}

@@ -507,27 +434,6 @@ sub format_iris_result_info {
	return ( $info, $moreinfo );
}

sub format_hafas_result_info {
	my ( $self, $result ) = @_;
	my ( $info, $moreinfo );

	$info = $result->info;
	if ($info) {
		$moreinfo = [ [ 'HAFAS', $info ] ];
	}
	if ( $result->delay and $result->delay > 0 ) {
		if ($info) {
			$info = 'ca. +' . $result->delay . ': ' . $info;
		}
		else {
			$info = 'ca. +' . $result->delay;
		}
	}
	push( @{$moreinfo}, map { [ 'HAFAS', $_ ] } $result->messages );

	return ( $info, $moreinfo );
}

sub render_train {
	my ( $self, $result, $departure, $station_name, $template ) = @_;

@@ -861,7 +767,6 @@ sub station_train_details {
	}

	my %opt = (
		cache_hafas     => $self->app->cache_hafas,
		cache_iris_main => $self->app->cache_iris_main,
		cache_iris_rt   => $self->app->cache_iris_rt,
	);
@@ -876,7 +781,7 @@ sub station_train_details {
	  ->subtract( minutes => 20 );
	$opt{lookahead} = 200;

	my $data   = get_results_for( 'iris', $station, %opt );
	my $data   = get_results_for( $station, %opt );
	my $errstr = $data->{errstr};

	if ( not @{ $data->{results} } ) {
@@ -1078,7 +983,6 @@ sub handle_result {
	my $hide_opts      = $self->param('hide_opts') // 0;
	my $show_realtime  = $self->param('show_realtime') // 0;
	my $show_details   = $self->param('detailed') // 0;
	my $backend        = $self->param('backend') // 'iris';
	my $admode         = $self->param('admode') // 'deparr';
	my $apiver         = $self->param('version') // 0;
	my $callback       = $self->param('callback');
@@ -1111,7 +1015,7 @@ sub handle_result {
		  map { [ $self->numeric_platform_part( $_->platform ), $_ ] } @results;
	}

	if ( $backend eq 'iris' and $show_realtime ) {
	if ($show_realtime) {
		if ( $admode eq 'arr' ) {
			@results = sort {
				( $a->arrival // $a->departure )
@@ -1131,30 +1035,20 @@ sub handle_result {
	for my $result (@results) {
		my $platform = ( split( qr{ }, $result->platform // '' ) )[0];
		my $delay    = $result->delay;
		if ( $backend eq 'iris' and $admode eq 'arr' and not $result->arrival )
		{
		if ( $admode eq 'arr' and not $result->arrival ) {
			next;
		}
		if (    $backend eq 'iris'
			and $admode eq 'dep'
		if ( $admode eq 'dep'
			and not $result->departure )
		{
			next;
		}
		my ( $info, $moreinfo );
		if ( $backend eq 'iris' ) {
			( $info, $moreinfo )
		my ( $info, $moreinfo )
		  = $self->format_iris_result_info( $template, $result );
		}
		else {
			( $info, $moreinfo ) = $self->format_hafas_result_info($result);
		}

		my $time     = $result->time;
		my $linetype = 'bahn';

		if ( $backend eq 'iris' ) {

		my @classes = $result->classes;
		if ( @classes == 0 ) {
			$linetype = 'ext';
@@ -1182,7 +1076,6 @@ sub handle_result {
				$time = $result->departure->strftime('%H:%M');
			}
		}
		}

		if ($hide_low_delay) {
			if ($info) {
@@ -1204,7 +1097,7 @@ sub handle_result {

				# no longer supported
				$self->handle_no_results_json(
					$backend, undef,
					undef,
					"JSON API version=${apiver} is no longer supported",
					$Travel::Status::DE::IRIS::VERSION
				);
@@ -1280,7 +1173,7 @@ sub handle_result {
				]
			);
		}
		elsif ( $backend eq 'iris' ) {
		else {
			push(
				@departures,
				{
@@ -1347,33 +1240,6 @@ sub handle_result {
				return;
			}
		}
		else {
			push(
				@departures,
				{
					time             => $time,
					train            => $result->train,
					train_type       => $result->type,
					destination      => $result->destination,
					platform         => $platform,
					changed_platform => $result->is_changed_platform,
					info             => $info,
					is_cancelled     => $result->can('is_cancelled')
					? $result->is_cancelled
					: undef,
					messages => {
						delay => [],
						qos   => [],
					},
					moreinfo         => $moreinfo,
					delay            => $delay,
					additional_stops => [],
					canceled_stops   => [],
					replaced_by      => [],
					replacement_for  => [],
				}
			);
		}
	}

	if ( $template eq 'json' ) {
Loading