misc.py 436 B

123456789101112131415
  1. import hashlib
  2. def get_gravatar_url(email):
  3. # Trim leading and trailing whitespace from
  4. # an email address and force all characters
  5. # to lower case
  6. address = str(email).strip().lower()
  7. # Create a SHA256 hash of the final string
  8. hash_object = hashlib.sha256(address.encode())
  9. hash_hex = hash_object.hexdigest()
  10. # Grab the actual image URL
  11. return f"https://www.gravatar.com/avatar/{hash_hex}?d=mp"