mirror of
https://github.com/revanced/revanced-static-api.git
synced 2025-04-30 06:34:30 +02:00
feat: Check if API is rate limited
This commit is contained in:
parent
38e93bc2f2
commit
de5f018d47
15
app/api.py
15
app/api.py
@ -7,6 +7,9 @@ class Api:
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self, api_key: str | None = None):
|
def __init__(self, api_key: str | None = None):
|
||||||
|
if (self.is_rate_limited()):
|
||||||
|
raise Exception('Api is rate limited.')
|
||||||
|
|
||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@ -41,10 +44,19 @@ class Api:
|
|||||||
organization (str): The organization to get the team for.
|
organization (str): The organization to get the team for.
|
||||||
'''
|
'''
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def is_rate_limited(self) -> bool:
|
||||||
|
"""Checks if the api is rate limited.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: Whether the api is rate limited or not.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
class GitHubApi(Api):
|
class GitHubApi(Api):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_contributor(self, repository):
|
def get_contributor(self, repository):
|
||||||
@ -143,3 +155,6 @@ class GitHubApi(Api):
|
|||||||
f'https://api.github.com/orgs/{organization}/members').json()
|
f'https://api.github.com/orgs/{organization}/members').json()
|
||||||
# List might not be needed.
|
# List might not be needed.
|
||||||
return list(map(transform_team_member, members))
|
return list(map(transform_team_member, members))
|
||||||
|
|
||||||
|
def is_rate_limited(self) -> bool:
|
||||||
|
return requests.get('https://api.github.com/rate_limit').json()["rate"]["remaining"] == 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user