summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-09-13 20:42:13 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-09-13 20:42:13 +0200
commit438505f1cb7c5542104f36626a14c6d59b7f475a (patch)
tree53c618518e6cffea9452ecd9430b5f1e209a0bd7
parentd99ac06ba7379c92809a2ca9b2285fac1639ce37 (diff)
add optional stats support
-rw-r--r--index.pl12
1 files changed, 12 insertions, 0 deletions
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(