avg-age 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 3 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, see <http://www.gnu.org/licenses/>.
  16. my $PageDir = 'page';
  17. my $Now = time;
  18. sub ParseData {
  19. my $data = shift;
  20. my %result;
  21. while ($data =~ /(\S+?): (.*?)(?=\n[^ \t]|\Z)/sg) {
  22. my ($key, $value) = ($1, $2);
  23. $value =~ s/\n\t/\n/g;
  24. $result{$key} = $value;
  25. }
  26. return %result;
  27. }
  28. local $/ = undef; # Read complete files
  29. my %Month = ();
  30. my %Age = ();
  31. my %Hits = ();
  32. # include dotfiles!
  33. foreach my $file (glob("$PageDir/*/*.pg $PageDir/*/.*.pg")) {
  34. next unless $file =~ m|/.*/(.+)\.pg$|;
  35. my $page = $1;
  36. open(F, $file) or die "Cannot read $page file: $!";
  37. my $data = <F>;
  38. close(F);
  39. my %result = ParseData($data);
  40. my $days = ($Now - $result{ts}) / (24 * 60 * 60);
  41. $Month{int($days/100)+1}++;
  42. $Age{$page} = $days;
  43. };
  44. print "Days\t#Pages\n";
  45. for my $key (reverse(sort { $a <=> $b } (keys %Month))) {
  46. print $key * 100, "\t", $Month{$key}, "\n";
  47. }