import hashlib


def gravatar(email):
    """
    Get a gravatar for an email address.

    Attempts to use Libravatar by default, but due to Github
    integration with Gravatar will fall back onto Gravatar

    """

    email = email.encode('utf8').lower()
    slug = hashlib.md5(email).hexdigest()
    libravatarURL = "https://seccdn.libravatar.org/avatar/"
    gravatarURL = "https://secure.gravatar.com/avatar/"
    return libravatarURL + slug + "?d=" + gravatarURL + slug