Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created September 20, 2024 20:42
Show Gist options
  • Select an option

  • Save KyMidd/fdb833dfc3b02323dab5923dd60be1e6 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/fdb833dfc3b02323dab5923dd60be1e6 to your computer and use it in GitHub Desktop.
# Check if hitting API rate-limiting
def hold_until_rate_limit_success():
while True:
response = requests.get(
url="https://api.github.com/rate_limit",
headers={
"Accept": "application/vnd.github.v3+json",
"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}"
}
)
if response.status_code != 200:
print("Error fetching rate limit info")
exit(1)
rate_limit_info = response.json()
remaining = rate_limit_info['rate']['remaining']
if remaining < 100:
print("ℹ️ We have less than 100 GitHub API rate-limit tokens left, sleeping for 1 minute and checking again")
time.sleep(60)
else:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment