mirror of
https://git.juggalol.com/agatha/gitmon.git
synced 2024-11-22 07:26:41 +00:00
Update docstrings
This commit is contained in:
parent
74288909ba
commit
bf34654a46
@ -12,6 +12,14 @@ setup_logger()
|
|||||||
|
|
||||||
class GitHubApi:
|
class GitHubApi:
|
||||||
def __init__(self, token=None, headers=None, proxy=None):
|
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.base_url = 'https://api.github.com'
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
|
|
||||||
@ -30,7 +38,16 @@ class GitHubApi:
|
|||||||
self.rate_remaining = None
|
self.rate_remaining = None
|
||||||
|
|
||||||
def __get(self, endpoint, params=None):
|
def __get(self, endpoint, params=None):
|
||||||
"""GET an HTTP resource and return JSON."""
|
"""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.
|
||||||
|
|
||||||
|
"""
|
||||||
url = self.base_url + endpoint
|
url = self.base_url + endpoint
|
||||||
|
|
||||||
# Check rate limits and sleep if exceeded
|
# Check rate limits and sleep if exceeded
|
||||||
@ -49,13 +66,26 @@ class GitHubApi:
|
|||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
def __parse_headers(self, headers):
|
def __parse_headers(self, headers):
|
||||||
"""Parse headers to update rate limits."""
|
"""Parse the response headers to update the rate limit information.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
headers (dict): The response headers from the GitHub API.
|
||||||
|
|
||||||
|
"""
|
||||||
self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset']))
|
self.rate_reset = datetime.fromtimestamp(int(headers['x-ratelimit-reset']))
|
||||||
self.rate_remaining = int(headers['x-ratelimit-remaining'])
|
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()})')
|
logger.info(f'{self.rate_remaining} calls remaining until {self.rate_reset} ({self.rate_reset - datetime.now()})')
|
||||||
|
|
||||||
def get_events(self, page=None):
|
def get_events(self, page=None):
|
||||||
"""Fetch GitHub events."""
|
"""Fetch GitHub events.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
page (int, optional): The page number of events to retrieve.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: The JSON response containing the events.
|
||||||
|
|
||||||
|
"""
|
||||||
endpoint = '/events'
|
endpoint = '/events'
|
||||||
params = None
|
params = None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user