Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[411ba2]: extras / gource / get_gravatars.pl Maximize Restore History

Download this file

get_gravatars.pl    103 lines (85 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#!/usr/bin/perl
# Hacked version of the example on http://code.google.com/p/gource/wiki/GravatarExample
# Make sure the config is correct before running this!
use strict; use warnings;
# Size, in px of the image
my $size = 80;
# Set the path to the POE git repo
my $gitpath = File::Spec->catdir( $ENV{HOME}, 'othergit', 'poe' );
# store the mapping between committer => PAUSE id for gravatar lookup
# http://poe.dyndns.org/~troc/notes/authors.txt # for the info :)
# This is up-to-date as of March 16, 2010
my %author_to_pauseid = (
'dhoss' => 'DHOSS',
'immute' => 'IMMUTE',
'bingosnet' => 'BINGOS',
'teknikill' => 'XANTUS',
'nothingmuch' => 'NUFFIN',
'sungo' => 'SUNGO',
'cfedde' => 'CFEDDE',
'lotr' => 'MARTIJN',
'root' => 'RCAPUTO',
'tarrantsun' => undef, # http://twitter.com/dscouch - I should add code to extract the profile pic from there, blah...
'hachi' => 'HACHI',
'bsmith' => 'BSMITH',
'rcaputo' => 'RCAPUTO',
'gwyn17' => 'GWYN',
'troc' => 'RCAPUTO',
'apocal' => 'APOCAL',
'adamkennedy' => 'ADAMK',
'(no author)' => 'RCAPUTO',
'cwest' => 'CTWETEN',
);
# END OF CONFIG
use LWP::Simple qw( getstore get );
use File::Spec;
my $output_dir = File::Spec->catdir( $gitpath, 'extras', 'gource', 'avatars' );
# First of all, we move to the git path
chdir( $gitpath ) or die "Unable to chdir to '$gitpath': $!\n";
if ( ! -d $output_dir ) {
mkdir( $output_dir ) or die "Unable to mkdir '$output_dir': $!\n";
}
# Process the git log!
open( my $gitlog, q/git log --pretty=format:"%an" |/ ) or die "Unable to read git-log: $!\n";
my %authors;
while( <$gitlog> ) {
chomp;
my $author = $_;
next if $authors{$author}++;
# skip images we have
my $author_image_file = File::Spec->catfile( $output_dir, $author . '.png' );
next if -e $author_image_file;
# Look up the email address of the PAUSE id, if any?
my $gravatar;
if ( exists $author_to_pauseid{ $author } ) {
# Some authors don't have a PAUSE id...
next if ! defined $author_to_pauseid{ $author };
# get it!
# I hate this crap code but URI::Find::Rule seems to bomb out trying to find the gravatar URL...
my $content = get( 'http://search.cpan.org/~' . $author_to_pauseid{ $author } );
if ( defined $content and $content =~ m|\<img\s+src\=\"http\://www\.gravatar\.com/avatar\.php\?gravatar_id\=([^\&]+)\&| ) {
$gravatar = $1;
} else {
warn "Unable to parse search.cpan.org for gravatar URL for '$author' PAUSEid: $author_to_pauseid{ $author }\n";
next;
}
} else {
warn "New committer to POE detected! Please update the mapping in this script for '$author'\n";
next;
}
# Fetch the image!
my $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=$gravatar&d=404&size=" . $size;
warn "Fetching image for '$author' ($grav_url)...\n";
my $rc = getstore( $grav_url, $author_image_file );
# Anything other than a 200 meant we didn't get the image
if ( $rc != 200 ) {
warn "PAUSE id '" . $author_to_pauseid{ $author } . "' for committer '$author' does not have a gravatar!\n";
if ( -e $author_image_file ) {
unlink( $author_image_file ) or die "Unable to remove '$author_image_file': $!\n";
}
}
# Give our internets some rest!
sleep 1;
}
# All done!
close $gitlog or die "Unable to close git-log: $!\n";