Skip to content

Instantly share code, notes, and snippets.

@GGontijo
Created January 8, 2024 14:37
Show Gist options
  • Save GGontijo/46de8c9285c6863db6d2f20a70386300 to your computer and use it in GitHub Desktop.
Save GGontijo/46de8c9285c6863db6d2f20a70386300 to your computer and use it in GitHub Desktop.
cooldown for python apis
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