From 113c9c00c6830f909e90212e29ca5e4a38cc2500 Mon Sep 17 00:00:00 2001 From: amine Date: Fri, 19 Jul 2024 02:49:11 +0200 Subject: [PATCH 1/6] style: apply black autoformatter --- retroachievements/client.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/retroachievements/client.py b/retroachievements/client.py index c2e2718..c08318c 100644 --- a/retroachievements/client.py +++ b/retroachievements/client.py @@ -10,8 +10,7 @@ class RAClient: Main class for accessing the RetroAhievements Web API """ - headers = { - "User-Agent": "RetroAchievements-api-python/" + __version__} + headers = {"User-Agent": "RetroAchievements-api-python/" + __version__} def __init__(self, username, api_key): self.username = username @@ -50,9 +49,7 @@ 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=0, recent_cheevos=10) -> dict: """ Get a user's exhaustive profile metadata @@ -96,8 +93,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: @@ -134,7 +130,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 From 63f047e4c2535f55a7b3c71b1c75cdeae0a058cb Mon Sep 17 00:00:00 2001 From: amine Date: Fri, 19 Jul 2024 02:55:03 +0200 Subject: [PATCH 2/6] style: add some type hints --- retroachievements/client.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/retroachievements/client.py b/retroachievements/client.py index c08318c..22c4d35 100644 --- a/retroachievements/client.py +++ b/retroachievements/client.py @@ -7,16 +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__} - 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 """ @@ -26,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( @@ -49,7 +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 @@ -120,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 From 637c4991b2d8cb7c5c70e4c970080da1a699560e Mon Sep 17 00:00:00 2001 From: amine Date: Fri, 19 Jul 2024 03:06:13 +0200 Subject: [PATCH 3/6] chore: add requirements files and add some notes to how to contribute --- CONTRIBUTING.md | 17 +++++++++++++++++ requirements-dev.in | 2 ++ requirements-dev.txt | 36 ++++++++++++++++++++++++++++++++++++ requirements.in | 1 + requirements.txt | 16 ++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 requirements-dev.in create mode 100644 requirements-dev.txt create mode 100644 requirements.in create mode 100644 requirements.txt 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/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 From a91435331b71653d01295f411a37cb46b03063b0 Mon Sep 17 00:00:00 2001 From: amine Date: Fri, 19 Jul 2024 03:06:22 +0200 Subject: [PATCH 4/6] chore: add .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore 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 From 15e1188b54c8398ca0a3c5488487d0f9a7322ba5 Mon Sep 17 00:00:00 2001 From: amine Date: Fri, 19 Jul 2024 03:07:34 +0200 Subject: [PATCH 5/6] docs: update README to use snake_case --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3addc7c..b890c7c 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(userName, webApiKey) ``` 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 From 815a3bc096ab151811d668431e9ad81808a518ac Mon Sep 17 00:00:00 2001 From: amine Date: Fri, 19 Jul 2024 03:16:21 +0200 Subject: [PATCH 6/6] docs: fix a typo where the variables must be in snake_case for the example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b890c7c..b0949b4 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ from retroachievements import RAClient user_name = '' web_api_key = '' -client = 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: