SHARE
TWEET

Friendster tool: summary.pl

Qwerty0 May 7th, 2011 334 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2. # For Archive Team Friendster project
  3. # http://archiveteam.org/index.php?title=Friendster
  4. #       This script will summarize your bff.sh's download progress with the
  5. # latest finished ID and percent complete for each instance as well as overall
  6. # percentage done, and even mini-progress bars! (screenshot: imgur.com/x2Hhd)
  7. #       You can print the status at any time by running summary.pl, and even
  8. # write a little loop to run it every minute so you always have a little
  9. # up-to-date status window:
  10. # $ while [ ! -e STOP ]; do ./summary.pl; sleep 60; done;
  11. #       The requirement is that you have a file "progress.txt" where your
  12. # bff.sh scripts log their finished profile IDs. For advanced stuff like
  13. # percent complete and progress bars, you also need a file "config.txt" where
  14. # information on your instances' starting configurations is stored. invoker.pl
  15. # can set up both for you (pastebin.com/HXtSDi42) or you do it yourself. For
  16. # "progress.txt" you just add a line to the loop that runs your bff.sh
  17. # instances: 'echo "#: $i" >> progress.txt' where "#" is the number of the
  18. # instance and $i is the profile ID it just finished. Whatever you do is fine
  19. # as long as it adheres to the format "[instance number]:[profile id]"
  20. # (whitespace ignored) and your instances append a line for every profile id
  21. # they finish. For "config.txt" it's simply a file with a line for each
  22. # instance saying which ID it started on, in the same format as "progress.txt":
  23. # "[instance number]:[starting profile id]" (whitespace ignored)
  24.  
  25. sub trim {
  26.         my $string = shift;
  27.         $string =~ s/^\s+//;
  28.         $string =~ s/\s+$//;
  29.         return $string;
  30. }
  31.  
  32. my $logfile = "progress.txt";
  33. my $confile = "config.txt";
  34. my $config = (-e $confile);
  35.  
  36. # You can also use a custom filename instead of progress.txt, given as an
  37. # argument: $ ./summary.pl yourfile.txt
  38. if (@ARGV > 0) {
  39.         $logfile = shift @ARGV;
  40. }
  41.  
  42. open FILEIN, "<", $logfile or die "Could not open logfile: $!";
  43. if ($config) {
  44.         open CONFIG, "<", $confile or warn "Could not open config file: $!";
  45. }      
  46.  
  47. # Reads the current file, stores the latest figures in a hash
  48. my %stats;
  49. my @fields;
  50. foreach my $line (<FILEIN>) {
  51.         @fields = split ":", $line;
  52.         if (@fields == 2) {
  53.                 chomp($fields[1]);
  54.                 $stats{trim($fields[0])} = trim($fields[1]);
  55.         }
  56. }
  57.  
  58. # Yeah, kinda kludgy but I was impatient and it's surprisingly hard to delete
  59. # a file using the same filehandle you just read from
  60. close FILEIN;
  61. open FILEOUT, ">", $logfile or die "Could not open logfile: $!";
  62.  
  63. my %begins;
  64. if ($config) {
  65.         foreach $line (<CONFIG>) {
  66.                 @fields = split ":", $line;
  67.                 if (@fields == 2) {
  68.                         chomp($fields[1]);
  69.                         $begins{trim($fields[0])} = trim($fields[1]);
  70.                 }
  71.         }
  72. }
  73.  
  74. my $range = $begins{2} - $begins{1};
  75. if (defined $range && $range < 1) { $range = 1 }
  76.  
  77. # Prints the values from the hash to the screen and back to the file
  78. my @inst = sort {$a <=> $b} keys %stats;
  79. my $lineout;
  80. my $pct;
  81. my $pctsum = 0;
  82. my $bar;
  83. foreach my $inst (@inst) {
  84.         $lineout = sprintf("%2d: %d", $inst, $stats{$inst});
  85.         print FILEOUT "$lineout\n";
  86.         print $lineout;
  87.         if ($config) {
  88.                 $pct = 100 * ($stats{$inst} - $begins{$inst} + 1)/$range;
  89.                 $pctsum += $pct;
  90.                 $bar = "=" x ($pct/7);
  91.                 printf "  %3d%%", $pct;
  92.                 print " $bar\n";
  93.         } else {
  94.                 print "\n";
  95.         }
  96. }
  97.  
  98. # Overall percent done for all instances
  99. printf "total: %3d%%\n", $pctsum/@inst;
  100.  
  101. close FILEOUT;
  102. close CONFIG;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top