Compare commits

..

No commits in common. "bf34654a4668d788acc94e6462e6f0ef53af99ea" and "5a4960a087d54173f3806e2292e026220db0bc80" have entirely different histories.

View File

@ -12,14 +12,6 @@ setup_logger()
class GitHubApi:
def __init__(self, token=None, headers=None, proxy=None):
"""Initialize the GitHubApi instance.
Args:
token (str, optional): GitHub API token.
headers (dict, optional): Additional headers to include in API requests.
proxy (dict, optional): Proxy information.
"""
self.base_url = 'https://api.github.com'
self.session = requests.Session()
@ -38,19 +30,10 @@ class GitHubApi:
self.rate_remaining = None
def __get(self, endpoint, params=None):
"""Send a GET request to the GitHub API and return the JSON response.
Args:
endpoint (str): The API endpoint.
params (dict, optional): Query parameters for the request.
Returns:
dict: The JSON response from the API.
"""
"""GET an HTTP resource and return JSON."""
url = self.base_url + endpoint
# Check rate limits and sleep if exceeded
# Check rate limits
if self.rate_remaining == 0 and self.rate_reset > datetime.now():
logger.warning(f'Out of API calls. Sleeping until {self.rate_reset}.')
delta = self.rate_reset - datetime.now()
@ -62,30 +45,21 @@ class GitHubApi:
logger.warning(f'Failed to execute GET request: {str(e)}')
return None
# 304 Not Modified
if response.status_code == '304':
return None
self.__parse_headers(response.headers)
return response.json()
def __parse_headers(self, headers):
"""Parse the response headers to update the rate limit information.
Args:
headers (dict): The response headers from the GitHub API.
"""
"""Parse headers to update rate limits."""
self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset']))
self.rate_remaining = int(headers['x-ratelimit-remaining'])
logger.info(f'{self.rate_remaining} calls remaining until {self.rate_reset} ({self.rate_reset - datetime.now()})')
def get_events(self, page=None):
"""Fetch GitHub events.
Args:
page (int, optional): The page number of events to retrieve.
Returns:
dict: The JSON response containing the events.
"""
"""Fetch GitHub events."""
endpoint = '/events'
params = None