summaryrefslogtreecommitdiff
path: root/index.pl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-09-13 20:42:07 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-09-13 20:42:07 +0200
commit2b8fdda37f6a76c9dc252e2d26a7fa75c9170526 (patch)
tree10a5cd80922a47301fb7ba0aec5e0330a3595030 /index.pl
parent372b5254b61925953c31ed192d32edc99a4798ee (diff)
add optional stats support
Diffstat (limited to 'index.pl')
-rw-r--r--index.pl12
1 files changed, 12 insertions, 0 deletions
diff --git a/index.pl b/index.pl
index 0e4ce3c..82cf7e7 100644
--- a/index.pl
+++ b/index.pl
@@ -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