Commit 2b8fdda3 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add optional stats support

parent 372b5254
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
#!/usr/bin/env perl
use Mojolicious::Lite;
use Cache::File;
use File::Slurp qw(read_file write_file);
use List::MoreUtils qw();
use Travel::Status::DE::DeutscheBahn;
use Travel::Status::DE::IRIS;
@@ -14,6 +15,14 @@ our $VERSION = qx{git describe --dirty} || '0.05';

my $refresh_interval = 180;

sub log_api_access {
	my $counter = 1;
	if ( -r $ENV{DBFAKEDISPLAY_STATS} ) {
		$counter = read_file( $ENV{DBFAKEDISPLAY_STATS} ) + 1;
	}
	write_file( $ENV{DBFAKEDISPLAY_STATS}, $counter );
}

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

@@ -33,6 +42,9 @@ sub get_results_for {
	my $data = $cache->thaw($cache_str);

	if ( not $data ) {
		if ( $ENV{DBFAKEDISPLAY_STATS} ) {
			log_api_access();
		}
		if ( $backend eq 'iris' ) {

			# requests with DS100 codes should be preferred (they avoid