Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup a bit #3

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Python
*.pyc
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
```
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<your username on RA>'
webApiKey = '<your web API key>'
user_name = '<your username on RA>'
web_api_key = '<your 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
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
black==24.4.2
pip-tools==7.4.1
36 changes: 36 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.32.3
16 changes: 16 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
31 changes: 17 additions & 14 deletions retroachievements/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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(
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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