#!/usr/bin/perl

use strict;
my $logfile = "/path/to/log/file/access.log";
#my $logfile = "access.log";
my %agents;
my %bot_ua = (
  'Hatena' => 'Hatena\x20RSS',
  'NewsAlloy' => 'NewsAlloy',
  'FreshReader' => 'FreshReader',
  'Feedpath' => 'Feedpath',
  'Google Reader' => 'Feedfetcher-Google',
  'Rojo' => 'Rojo',
  'Bloglines' => 'Bloglines',
  'Livedoor Reader' => 'livedoor\x20FeedFetcher',
  'FastLadder' => 'Fastladder\x20FeedFetcher',
);
open(FILE, "<$logfile");
while(<FILE>) {
  my $line = $_;
  if ((my $ua) = grep {$line =~ /$bot_ua{$_}/} keys(%bot_ua)) {
	if ($line =~ ' subscriber') {
		$line =~ s/^.* ([0-9]+) subscriber.*\n$/\1/;
		$agents{$ua} = $line if ($agents{$ua} < $line);
	}
  }
}
close(FILE);

print <<EOF
Content-Type: text/html;

<html>
<head><title>Your Feeds Subscriber</title><head>
<body>
<table border=\"1\">
EOF
;
my $sum = 0;
while(my ($key, $value) = each(%agents)) {
  print "<tr><td>$key</td><td>$value</td></tr>\n";
  $sum += $value;
}
print <<EOF
<tr style="background: gray;"><td>total</td><td>$sum</td></tr>
</table>
</body>
</html>
EOF
;
