From 47e2bda1812e41aa4cf93906d6a43db2927accc3 Mon Sep 17 00:00:00 2001 From: agatha Date: Fri, 10 Nov 2023 20:30:33 -0500 Subject: [PATCH] Track rate limit reset and remaining --- gitmon/api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gitmon/api.py b/gitmon/api.py index f9abda8..4fa6cc5 100644 --- a/gitmon/api.py +++ b/gitmon/api.py @@ -18,6 +18,10 @@ class GitHubApi: if proxy: self.session.proxies.update(proxy) + # Rate limits + self.rate_reset = None + self.rate_remaining = None + def __get(self, endpoint, params=None): """GET an HTTP resource and return JSON.""" url = self.base_url + endpoint @@ -33,7 +37,8 @@ class GitHubApi: def __parse_headers(self, headers): """Parse headers to update rate limits.""" - pass + self.rate_reset = int(headers['x-ratelimit-reset']) + self.rate_remaining = int(headers['x-ratelimit-remaining']) def get_events(self, page=None): """Fetch GitHub events."""