Cory Wright wrote in with his method for generating Gravatar URLs in python (seems to require 2.5 or better.) It’s truly great when we get submissions like this. Not only do we get to see how people are using Gravatar, but we get to share that information to help other people who might be thinking about using Gravatar themselves!
# import code for encoding urls and generating md5 hashes import urllib, hashlib # Set your variables here email = "Someone@somewhere.com" default = "http://www.somewhere.com/homsar.jpg" size = 40 # construct the url gravatar_url = "http://www.gravatar.com/avatar.php?" gravatar_url += urllib.urlencode({'gravatar_id':hashlib.md5(email.lower()).hexdigest(), 'default':default, 'size':str(size)})
Comments
11 responses to “Gravatars in Python 2.5”
To get it to work in python version previous to 2.5, import the MD5 this way:
try:
from hashlib import md5
except ImportError:
import md5
md5 = md5.new
Argh, wordpress ate my indents. Also, for the alternative import to work “hashlib.md5” needs to be changed to “md5” in the rest of the code.
[…] stata scritta l’implementazione di Gravatar in Python: per chi serve e si vuole risparmiare 11 righe di codice. « […]
test. please delete
Very good piece of code.
Gravatar is very easy to implement with Python. I’m using in some projects. I hope see a good integration of Gravatar with WordPress 2.4. 😉
Good luck, silveira, since WP 2.4 won’t be released. 😉
Isn’t the md5 encoding of e-mail addresses vulnerable to harvesting by ne’er-do-wells?
yayayya
Well written.
ohh..thanks
Thanks..