diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdb2b9b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Python +*.pyc \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 854139a..1280244 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1 +1,18 @@ # Contributing +## Install depedencies +To contribute to this project, you will need to install both the user and dev requirements +``` +pip install -r requirements.txt +pip install -r requirements-dev.txt +``` + +## Update requirement files +To update the user dependencies: +``` +pip-compile requirements.in +``` + +To update the dev requirements: +``` +pip-compile requirements-dev.in +``` \ No newline at end of file diff --git a/README.md b/README.md index 3addc7c..b0949b4 100644 --- a/README.md +++ b/README.md @@ -53,20 +53,18 @@ To use any endpoint function in the API, you must first be authorized by RetroAc ```python from retroachievements import RAClient -userName = '' -webApiKey = '' +user_name = '' +web_api_key = '' -auth = RAClient(userName, webApiKey) +client = RAClient(user_name, web_api_key) ``` 4. You now have all you need to use any function in the API. Each function takes this authorization object as its first argument. Here's an example: ```python -from retroachievements import getGame - // This returns basic metadata about the game on this page: // https://retroachievements.org/game/14402 -game = auth.getGame(14402); +game = client.get_game(14402); ``` ## Contributing diff --git a/requirements-dev.in b/requirements-dev.in new file mode 100644 index 0000000..a9a6b9f --- /dev/null +++ b/requirements-dev.in @@ -0,0 +1,2 @@ +black==24.4.2 +pip-tools==7.4.1 \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..d311d6b --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,36 @@ +# +# This file is autogenerated by pip-compile with Python 3.12 +# by the following command: +# +# pip-compile requirements-dev.in +# +black==24.4.2 + # via -r requirements-dev.in +build==1.2.1 + # via pip-tools +click==8.1.7 + # via + # black + # pip-tools +mypy-extensions==1.0.0 + # via black +packaging==24.1 + # via + # black + # build +pathspec==0.12.1 + # via black +pip-tools==7.4.1 + # via -r requirements-dev.in +platformdirs==4.2.2 + # via black +pyproject-hooks==1.1.0 + # via + # build + # pip-tools +wheel==0.43.0 + # via pip-tools + +# The following packages are considered to be unsafe in a requirements file: +# pip +# setuptools diff --git a/requirements.in b/requirements.in new file mode 100644 index 0000000..ef487e0 --- /dev/null +++ b/requirements.in @@ -0,0 +1 @@ +requests==2.32.3 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..34159dc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,16 @@ +# +# This file is autogenerated by pip-compile with Python 3.12 +# by the following command: +# +# pip-compile requirements.in +# +certifi==2024.7.4 + # via requests +charset-normalizer==3.3.2 + # via requests +idna==3.7 + # via requests +requests==2.32.3 + # via -r requirements.in +urllib3==2.2.2 + # via requests diff --git a/retroachievements/client.py b/retroachievements/client.py index c2e2718..22c4d35 100644 --- a/retroachievements/client.py +++ b/retroachievements/client.py @@ -7,17 +7,16 @@ class RAClient: """ - Main class for accessing the RetroAhievements Web API + Main class for accessing the RetroAchievements Web API """ - headers = { - "User-Agent": "RetroAchievements-api-python/" + __version__} + headers = {"User-Agent": "RetroAchievements-api-python/" + __version__} - def __init__(self, username, api_key): + def __init__(self, username: str, api_key: str): self.username = username self.api_key = api_key - def url_params(self, params=None): + def url_params(self, params: dict | None = None): """ Inserts the auth and query params into the request """ @@ -27,7 +26,13 @@ def url_params(self, params=None): return params # URL construction - def _call_api(self, endpoint=None, params=None, timeout=30, headers=None): + def _call_api( + self, + endpoint: dict | None = None, + params: dict | None = None, + timeout: int = 30, + headers: dict | None = None, + ): if endpoint is None: endpoint = {} req = request.get( @@ -50,9 +55,9 @@ def get_user_points(self, user: str) -> dict: result = self._call_api("API_GetUserPoints.php?", {"u": user}).json() return result - def get_user_summary(self, user: str, - recent_games=0, - recent_cheevos=10) -> dict: + def get_user_summary( + self, user: str, recent_games: int = 0, recent_cheevos: int = 10 + ) -> dict: """ Get a user's exhaustive profile metadata @@ -96,8 +101,7 @@ def get_achievement_count(self, game: int) -> dict: Params: i: The game ID to query """ - result = self._call_api( - "API_GetAchievementCount.php?", {"i": game}).json() + result = self._call_api("API_GetAchievementCount.php?", {"i": game}).json() return result def get_achievement_distribution(self, game: int) -> dict: @@ -124,7 +128,7 @@ def get_console_ids(self) -> list: result = self._call_api("API_GetConsoleIDs.php?", {}).json() return result - def get_game_list(self, system: int, has_cheevos=0, hashes=0) -> dict: + def get_game_list(self, system: int, has_cheevos: int = 0, hashes: int = 0) -> dict: """ Get the complete list of games for a console @@ -134,7 +138,6 @@ def get_game_list(self, system: int, has_cheevos=0, hashes=0) -> dict: h: If 1, also return the supported hashes for games (default = 0) """ result = self._call_api( - "API_GetGameList.php?", { - "i": system, "f": has_cheevos, "h": hashes} + "API_GetGameList.php?", {"i": system, "f": has_cheevos, "h": hashes} ).json() return result