misc.py 672 B

1234567891011121314151617181920212223
  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"
  12. def calculate_sha256(file):
  13. sha256 = hashlib.sha256()
  14. # Read the file in chunks to efficiently handle large files
  15. for chunk in iter(lambda: file.read(8192), b""):
  16. sha256.update(chunk)
  17. return sha256.hexdigest()