Skip to content

Instantly share code, notes, and snippets.

@macagua
Created June 20, 2014 04:20
Show Gist options
  • Save macagua/5c2f5e4e38df92aae7fe to your computer and use it in GitHub Desktop.
Save macagua/5c2f5e4e38df92aae7fe to your computer and use it in GitHub Desktop.
Python Gravatar Example for Gource software
# -*- coding: utf-8 -*-
#fetch Gravatars
# https://code.google.com/p/gource/wiki/GravatarExample
import os
import requests
import subprocess
import hashlib
def md5_hex(text):
m = hashlib.md5()
m.update(text.encode('ascii', errors='ignore'))
return m.hexdigest()
size = 90
output_dir = os.path.join('.git', 'avatar')
os.makedirs(output_dir, exist_ok=True)
gitlog = subprocess.check_output(['git', 'log', '--pretty=format:%ae|%an'])
authors = set(gitlog.decode('ascii', errors='ignore').splitlines())
print(authors)
for author in authors:
email, name = author.split('|')
output_file = os.path.join(output_dir, name + '.png')
if not os.path.exists(output_file):
grav_url = "http://www.gravatar.com/avatar/" + md5_hex(email) + "?d=identicon&s=" + str(size)
print(email, name, grav_url)
r = requests.get(grav_url)
if r.ok:
with open(output_file, 'wb') as img:
img.write(r.content)
@eliezerfot123
Copy link

It's very well! Thanks

@openp2pdesign
Copy link

Many thanks for this script!
I've forked it and added a search for the avatars on GitHub functionality before searching for them on Gravatar: https://gist.github.com/openp2pdesign/15db406825a4b35783e2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment