From 438505f1cb7c5542104f36626a14c6d59b7f475a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 13 Sep 2015 20:42:13 +0200 Subject: add optional stats support --- index.pl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.pl b/index.pl index 352d67a..c36d92e 100644 --- a/index.pl +++ b/index.pl @@ -6,6 +6,7 @@ use utf8; use DateTime; use DateTime::Format::Strptime; use Encode qw(decode); +use File::Slurp qw(read_file write_file); use List::Util qw(first); use List::MoreUtils qw(any); @@ -31,6 +32,14 @@ my %default = ( my @efa_services = map { $_->{shortname} } Travel::Status::DE::EFA::get_efa_urls(); +sub log_api_access { + my $counter = 1; + if ( -r $ENV{VRRFAKEDISPLAY_STATS} ) { + $counter = read_file( $ENV{VRRFAKEDISPLAY_STATS} ) + 1; + } + write_file( $ENV{VRRFAKEDISPLAY_STATS}, $counter ); +} + sub get_results { my ( $backend, $city, $stop, $expiry ) = @_; my $sub_backend; @@ -58,6 +67,9 @@ sub get_results { my $data = $cache->thaw($sstr); if ( not $data ) { + if ( $ENV{VRRFAKEDISPLAY_STATS} ) { + log_api_access(); + } my $status; if ( $backend eq 'db' ) { $status = Travel::Status::DE::DeutscheBahn->new( -- cgit v1.2.3