You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2 KiB

  1. #!/usr/bin/perl
  2. #
  3. # Author: Alain Schroeder
  4. # Date: 2005-07-09
  5. # Modified by Petter Reinholdtsen 2005-07-15
  6. use strict;
  7. my %table;
  8. my $foundentry = 0;
  9. my $ignorecount = 0;
  10. my $debug = 0;
  11. open (PACKAGES, '< packages') or
  12. die ("packages not found. please run clean-genpkglist first\n");
  13. while (<PACKAGES>) {
  14. chomp;
  15. $table{$_} = "1";
  16. }
  17. close PACKAGES;
  18. # Truncate timestamps to the start of the day, to avoid giving out
  19. # timezone information.
  20. sub fuzzy_timestamp {
  21. my $timestamp = shift;
  22. return 86400 * int($timestamp / 86400);
  23. }
  24. while (my $line = <STDIN>) {
  25. if ($line =~ m/^POPULARITY-CONTEST-0/i) {
  26. $foundentry = 1;
  27. $ignorecount = 0;
  28. $line =~ s/\b(TIME:)(\d+)\b/sprintf("%s%s", $1,fuzzy_timestamp($2))/e;
  29. } elsif ($line =~ m/^END-POPULARITY-CONTEST-0/i) {
  30. $foundentry = 0;
  31. print "# Ignored $ignorecount entries\n";
  32. $line =~ s/\b(TIME:)(\d+)\b/sprintf("%s%s", $1,fuzzy_timestamp($2))/e;
  33. } elsif ($line =~ m/^\d+ \d+ (\S*).*/i && !exists $table{$1}) {
  34. print STDERR "Ignoring package $1\n" if $debug;
  35. $ignorecount++;
  36. next;
  37. } elsif ($line =~ m/^(\d+) (\d+) (\S+) (.+)$/i && exists $table{$3}) {
  38. # Package entry
  39. $line = sprintf("%d %d %s %s\n", fuzzy_timestamp($1),
  40. fuzzy_timestamp($2), $3, $4);
  41. }
  42. print $line;
  43. }