圆月山庄资源网 Design By www.vgjia.com

Gravatar注册地址: https://en.gravatar.com/

复制代码 代码如下:
"""`Gravatar <https://en.gravatar.com/site/implement/>`_"""

# 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=404'
        try:
            urllib2.urlopen(gravatar_url)
        except 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)

标签:
urllib2,gravatar头像

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com