getavatars.pl 993 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/perl
  2. #fetch Gravatars
  3. use strict;
  4. use warnings;
  5. use LWP::Simple;
  6. use Digest::MD5 qw(md5_hex);
  7. my $size = 90;
  8. my $output_dir = './avatars';
  9. die("no .git/ directory found in current path\n") unless -d './avatars';
  10. mkdir($output_dir) unless -d $output_dir;
  11. open(GITLOG, q/git log --pretty=format:"%ae|%an" |/) or die("failed to read git-log: $!\n");
  12. my %processed_authors;
  13. while(<GITLOG>) {
  14. chomp;
  15. my($email, $author) = split(/\|/, $_);
  16. next if $processed_authors{$author}++;
  17. my $author_image_file = $output_dir . '/' . $author . '.png';
  18. #skip images we have
  19. next if -e $author_image_file;
  20. #try and fetch image
  21. my $grav_url = "http://www.gravatar.com/avatar/".md5_hex(lc $email)."?d=404&size=".$size;
  22. warn "fetching image for '$author' $email ($grav_url)...\n";
  23. my $rc = getstore($grav_url, $author_image_file);
  24. sleep(1);
  25. if($rc != 200) {
  26. unlink($author_image_file);
  27. next;
  28. }
  29. }
  30. close GITLOG;