diff options
author | Daniel Friesel <derf@finalrewind.org> | 2015-09-13 20:42:07 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2015-09-13 20:42:07 +0200 |
commit | 2b8fdda37f6a76c9dc252e2d26a7fa75c9170526 (patch) | |
tree | 10a5cd80922a47301fb7ba0aec5e0330a3595030 /index.pl | |
parent | 372b5254b61925953c31ed192d32edc99a4798ee (diff) |
add optional stats support
Diffstat (limited to 'index.pl')
-rw-r--r-- | index.pl | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -1,6 +1,7 @@ #!/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 |