This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from time import perf_counter # perf_counter is a highly quality timestamp | |
# Keys are the functions themselves, values are a tuple containing the timeout expiry | |
# of the cache entry, and the cached return value. | |
function_cache = {} | |
def timeout_cache(seconds: int or float): | |
def check_timeout_cache(wrapped_func): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from datetime import timedelta | |
import pytz | |
from dateutil import tz | |
def timedelta_to_label(td: timedelta) -> str: | |
""" returns a string like +1:00 """ | |
label = "-" + str(abs(td)) if td.total_seconds() < 0 else "+" + str(abs(td)) | |
return label[:-3] |