Created
April 15, 2015 04:54
-
-
Save hustlzp/e938991013044e35cff6 to your computer and use it in GitHub Desktop.
Get image from gravatar.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import hashlib | |
import requests | |
import shutil | |
email = "[email protected]" | |
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