Commit 057e9576 authored by Ken Fallon's avatar Ken Fallon

2016-08-22_18-45-35_CEST

parent fc3c8b99
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use DateTime::Format::ISO8601;
use Digest::MD5 qw(md5_hex);
# (c) Ken Fallon hpr@kenfallon.com
# Released under the http://www.gnu.org/licenses/agpl-3.0.html
my %mon2num = qw( Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06 Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12 );
my ( %hits, %results );
my $total;
my $random_number = rand();
my $out_file = "report.txt";
open (my $out_handle, '>', $out_file) or die $!;
while ( my $in_file = shift ) {
next "$in_file is not a file\n" unless -e $in_file;
print STDERR "Processing $in_file\n";
open (my $in_handle, '<', $in_file) or die $!;
while ( defined(my $thisline = <$in_handle>) ){
chomp $thisline;
next if ( $thisline =~ m/ \/(bot|spider|slurp|Craw|google)/ );
next unless ( $thisline =~ /GET \/eps\/hpr\d{4}\./ );
my ($ip1, $ip2, $ip3, $ip4, $j1, $j2, $day, $mon, $year, $hour, $min, $sec, $zone, $j3, $j4, $episode, $ext, @junk) = split /[:,\s\/\[\]\.]+/, $thisline;
next unless ( ( $ext =~ /mp3/ ) or ( $ext =~ /ogg/ ) or ( $ext =~ /spx/ ) );
next unless ( length($episode) == 7 );
# Over kill I know but a day is a UTC day
my $this_isodate = "${year}-" . $mon2num{"${mon}"} . "-${day}T${hour}:${min}:${sec}" . substr(${zone}, 0, 3) . ":" . substr(${zone}, 3, 2);
my ($this_epoch, $dt);
if (eval { $dt = DateTime::Format::ISO8601->parse_datetime($this_isodate); } ) {
$this_epoch = $dt->strftime('%s');
}
my $date = DateTime->from_epoch(epoch => $this_epoch, time_zone => 'UTC');
$this_isodate = $date->ymd();
if (eval { $dt = DateTime::Format::ISO8601->parse_datetime($this_isodate); } ) {
$this_epoch = $dt->strftime('%s');
}
# Scramble the IP addresses with some salt
my $ip_hash = md5_hex("${random_number}_${ip1}.${ip2}.${ip3}.${ip4}");
# Makes unique
$hits{ "${episode}#${this_isodate}#${ip_hash}" } = 1;
}
}
while ( my ($key, $value) = each(%hits) ) {
my ( $episode, $date, $hit) = split /#/, $key;
${results}{$episode}{$date}++;
${results}{"total"}{$date}++;
${results}{"total"}{$episode}++;
$total++;
}
for my $episode ( sort keys %results ) {
for my $date ( sort keys %{$results{$episode}} ) {
print $out_handle "$episode\t$date\t$results{$episode}{$date}\n";
}
}
print $out_handle "${total}\n";
close $out_handle;
exit;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment