Python use urllib2 module to get gravatar Avatar instance, you refer to use it Gravatar registration address: https://en.gravatar.com/
The code is as follows:
"'Gravatar
# Import code for encoding urls and generating md5 hashes
Import urllib2, hashlib
# Make response slow if verify whether default avatar or not.
# So let js do it, see '/static/js/article. js '.
Def gravatar_url (email, size = 40, verify_default = False ):
"Construct the gravatar url ."""
Gravatar_url = ''. join (['http: // www.gravatar.com/avatar /',
Hashlib. md5 (email. lower (). hexdigest (),'? S = % d' % size])
# If default return None
If (verify_default ):
Gravatar_url + = '& d = 100'
Try:
Urllib2.urlopen (gravatar_url)
Failed T urllib2.URLError, e:
Return None
Return gravatar_url
If _ name _ = '_ main __':
Import webbrowser as wb
For email in ['XXX @ gmail.com ']:
Url = gravatar_url (email)
Print (url)
If url:
Wb. open (url)