Skip to content

Instantly share code, notes, and snippets.

@dev4Fun
Created February 7, 2020 04:04
Show Gist options
  • Select an option

  • Save dev4Fun/013a392680b854d01541274cdb32bf20 to your computer and use it in GitHub Desktop.

Select an option

Save dev4Fun/013a392680b854d01541274cdb32bf20 to your computer and use it in GitHub Desktop.
# in bot.py
def _retry_rate_limited_failure(self, error_msg, func, *args, **kwargs):
error_msg = error_msg.lower()
search_term = "try again in "
if search_term in error_msg:
minute_idx = error_msg.index(search_term) + len(search_term)
if error_msg[minute_idx].isdigit():
digits = [error_msg[minute_idx]]
if error_msg[minute_idx + 1].isdigit():
digits.append(error_msg[minute_idx + 1])
wait_time_in_min = int(''.join(digits))
logging.info(f"{self.username} will attempt a second run after waiting for {wait_time_in_min} minutes")
wait_time_sec = wait_time_in_min * 60
sleep(random.randint(wait_time_sec + 10))
func(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment