Skip to content

Instantly share code, notes, and snippets.

View alanhamlett's full-sized avatar

Alan Hamlett alanhamlett

View GitHub Profile
@alanhamlett
alanhamlett / logger.py
Created September 6, 2022 00:21
WakaQ example worker error log handler
from logging import getLogger, ERROR, Formatter, Filter
from logging.handlers import WatchedFileHandler
from wakatime import app
from wakatime.background import wakaq
TASK_LOG_FORMAT = '[%(asctime)s] %(hostname)s %(levelname)s in %(task)s args=%(task_args)s kwargs=%(task_kwargs)s retry=%(task_retry)s: %(message)s'
class TaskFilter(Filter):
@alanhamlett
alanhamlett / image_utils.py
Last active September 24, 2022 08:07
Utility functions to resize, make square, and optimize (pngquant) images using Python
from io import BytesIO
from subprocess import PIPE, Popen
from typing import Optional
from PIL import Image, ImageFile, UnidentifiedImageError
from PIL.Image import DecompressionBombError
SUPPORTED_IMAGE_FORMATS = ["PNG", "JPEG", "JPEG2000"]
"""
wakatime.geocoding_utils
~~~~~~~~~~~~~~~~~~~~~~~~
Utils to get location from ip address.
"""
import traceback
import flag # https://pypi.org/project/emoji-country-flag