Skip to content

Instantly share code, notes, and snippets.

@hustlzp
Created April 15, 2015 04:54
Show Gist options
  • Save hustlzp/e938991013044e35cff6 to your computer and use it in GitHub Desktop.
Save hustlzp/e938991013044e35cff6 to your computer and use it in GitHub Desktop.
Get image from gravatar.
import urllib
import hashlib
import requests
import shutil
email = "example@gmail.com"
image_path = "/tmp/example.png"
gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(
user.email.lower()).hexdigest() + ".png?"
gravatar_url += urllib.urlencode({'d': str(404), 's': str(160)})
r = requests.get(gravatar_url, stream=True)
if r.status_code == 200:
with open(image_path, 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment