2024-01-29 20:26:56 -05:00
|
|
|
from ratelimit.decorators import sleep_and_retry
|
2024-01-28 20:29:19 -05:00
|
|
|
import requests
|
2024-01-29 20:26:56 -05:00
|
|
|
from ratelimit import limits, RateLimitException
|
|
|
|
|
from backoff import expo, on_exception
|
2024-01-28 20:29:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Leetify:
|
|
|
|
|
api_base_url = "https://api.leetify.com/api"
|
|
|
|
|
profile_base_url = f"{api_base_url}/profile"
|
|
|
|
|
match_base_url = f"{api_base_url}/games"
|
|
|
|
|
|
2024-01-31 19:38:08 -05:00
|
|
|
@on_exception(expo, Exception, max_tries=3)
|
2024-01-29 20:26:56 -05:00
|
|
|
@sleep_and_retry
|
|
|
|
|
@limits(1, 5)
|
2024-01-28 20:29:19 -05:00
|
|
|
def __get_page(self, url: str) -> dict:
|
|
|
|
|
resp = requests.get(url)
|
|
|
|
|
return resp.json()
|
|
|
|
|
|
|
|
|
|
def get_profile(self, id: str) -> dict:
|
|
|
|
|
url = f"{self.profile_base_url}/{id}"
|
|
|
|
|
return self.__get_page(url)
|
|
|
|
|
|
|
|
|
|
def get_match(self, id: str) -> dict:
|
|
|
|
|
url = f"{self.match_base_url}/{id}"
|
|
|
|
|
return self.__get_page(url)
|