-
-
Save KyMidd/fdb833dfc3b02323dab5923dd60be1e6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # 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