Python uses the urllib2 module to obtain the gravatar Avatar instance

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.