Skip to content

Instantly share code, notes, and snippets.

@enmaku
Created March 31, 2014 22:21
Show Gist options
  • Save enmaku/9903677 to your computer and use it in GitHub Desktop.
Save enmaku/9903677 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#fetch Gravatars
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')
try: os.makedirs(output_dir)
except: pass
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('|')
name = "".join([c for c in name if c.isalpha() or c.isdigit() or c==' ']).rstrip()
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment