avg-age 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /usr/bin/perl
  2. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the
  16. # Free Software Foundation, Inc.
  17. # 59 Temple Place, Suite 330
  18. # Boston, MA 02111-1307 USA
  19. my $PageDir = 'page';
  20. my $Now = time;
  21. sub ParseData {
  22. my $data = shift;
  23. my %result;
  24. while ($data =~ /(\S+?): (.*?)(?=\n[^ \t]|\Z)/sg) {
  25. my ($key, $value) = ($1, $2);
  26. $value =~ s/\n\t/\n/g;
  27. $result{$key} = $value;
  28. }
  29. return %result;
  30. }
  31. local $/ = undef; # Read complete files
  32. my %Month = ();
  33. my %Age = ();
  34. my %Hits = ();
  35. # include dotfiles!
  36. foreach my $file (glob("$PageDir/*/*.pg $PageDir/*/.*.pg")) {
  37. next unless $file =~ m|/.*/(.+)\.pg$|;
  38. my $page = $1;
  39. open(F, $file) or die "Cannot read $page file: $!";
  40. my $data = <F>;
  41. close(F);
  42. my %result = ParseData($data);
  43. my $days = ($Now - $result{ts}) / (24 * 60 * 60);
  44. $Month{int($days/100)+1}++;
  45. $Age{$page} = $days;
  46. };
  47. print "Days\t#Pages\n";
  48. for my $key (reverse(sort { $a <=> $b } (keys %Month))) {
  49. print $key * 100, "\t", $Month{$key}, "\n";
  50. }