Fetching script

This commit is contained in:
Matt Troutman 2024-07-17 13:34:16 -05:00
parent cd1588e578
commit 5ddc8c17e1
Signed by: trtmn
SSH Key Fingerprint: SHA256:cgYdsbnbA0S6X4anVowEAntjEpGV7nMyk2NW6ZYoNjE

View File

@ -0,0 +1,37 @@
# Script to grab the current Gravatar image for a given email address
import hashlib
import requests
def hash_email(email):
return hashlib.sha256(email.encode('utf-8')).hexdigest()
def fetch_gravatar(email="matt@trtmn.com", size=1000, rating="g"):
url = f"https://www.gravatar.com/avatar/{hash_email(email)}?s={size}&r={rating}"
print(url)
response = requests.get(url)
return response.content
def save_gravatar(email, size=1000, rating="g"):
with open(f"gravatar-{size}.png", "wb") as f: # Use "wb" mode for binary write
f.write(fetch_gravatar(email, size))
# Convert to webp format
import PIL
from PIL import Image
def convert_to_webp(size=1000):
im = Image.open(f"gravatar-{size}.png")
im.save(f"gravatar-{size}.webp")
def variety_of_sizes(email,sizes=[1000,1500,800,300,200,150,100]):
for x in sizes:
save_gravatar(email, size=x)
convert_to_webp(size=x)
if __name__ == '__main__':
# print( hash_email(email))
variety_of_sizes("matt@trtmn.com")