Skip to content

Instantly share code, notes, and snippets.

View milosev1c's full-sized avatar

Artem Milosevic milosev1c

View GitHub Profile
@milosev1c
milosev1c / webp_image_field.py
Created April 4, 2023 19:15
WebpImageField for Django
from io import BytesIO
from django.db.models.fields.files import ImageField
from PIL import Image
"""
This field will automatically convert your jpg/png files to webp
Usage:
Replace your ImageField with this one.
Parameters:
webp_quality: Integer, 0-100, Defaults to 80. For lossy, 0 gives the smallest size and 100 the largest.
@milosev1c
milosev1c / check_hash.py
Created December 16, 2022 12:47
how to check telegram auth
def check_hash(body):
secret_key = sha256(os.environ.get("TG_TOKEN", "").encode()).digest()
hash_string = body.pop("hash")
data_string = [f"{key}={value}" for key, value in body.items()]
data_string = "\n".join(sorted(data_string))
return hmac.new(secret_key, data_string.encode(), sha256).hexdigest() == hash_string