a little cleanup

This commit is contained in:
Matt Troutman 2024-09-05 01:44:58 -05:00
parent b9b1a3bd84
commit 9eefa13058
Signed by: trtmn
SSH Key Fingerprint: SHA256:cgYdsbnbA0S6X4anVowEAntjEpGV7nMyk2NW6ZYoNjE

View File

@ -1,9 +1,10 @@
# Script to grab the current Gravatar image for a given email address
import hashlib
import requests
import sys
from PIL import Image
# allow script to receive an argument
import sys
email_input = sys.argv[1]
def hash_email(email):
@ -15,27 +16,18 @@ def fetch_gravatar(email, size=1000, rating="g"):
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]):
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(email_input)
variety_of_sizes(email_input)