Fetching script
This commit is contained in:
parent
e9eae41847
commit
6a8085124d
37
Avatars/Current Gravatar/fetch.py
Normal file
37
Avatars/Current Gravatar/fetch.py
Normal 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="", 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("")
|
Loading…
Reference in New Issue
Block a user