Created
January 8, 2024 14:37
-
-
Save GGontijo/46de8c9285c6863db6d2f20a70386300 to your computer and use it in GitHub Desktop.
cooldown for python apis
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
last_execution = datetime.now(tz=pytz.timezone('America/Cuiaba')) | |
def cooldown(): | |
global last_execution | |
now = datetime.now(tz=pytz.timezone('America/Cuiaba')) | |
if last_execution is not None: | |
difference_time = (now - last_execution).seconds | |
remaining_time = 120 - difference_time | |
if difference_time < 120: | |
raise Exception(f'Please wait {remaining_time} seconds before another try!') | |
last_execution = now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment