A Python library for Oldschool RuneScape.
Project description
pyosrs - Python Library for Old School RuneScape
pyosrs is a Python library that provides a simple interface for retrieving and parsing data from the Old School RuneScape hiscores.
Installation
To install pyosrs, you can use pip:
pip install pyosrs
Usage
Retrieving Hiscores
To retrieve the hiscore for a player, you can create a Pyosrs instance and use its get_hiscore method. Here's an example:
import asyncio
from pyosrs.client import Pyosrs
from pyosrs.enums import GAME_MODE
async def main():
async with Pyosrs() as pyosrs:
hiscore = await pyosrs.get_hiscore("username")
# With game mode
hiscore = await pyosrs.get_hiscore("username", GAME_MODE.MAIN)
print(hiscore.skills.overall.rank)
print(hiscore.skills.overall.level)
print(hiscore.skills.overall.experience)
asyncio.run(main())
This will output the overall rank, level, and experience for the player in the main game mode.
Retrieving Game Mode
To retrieve the game mode for a player, you can use get_game_mode method which returns a tuple of the game mode and the player's hiscore object. Here's an example:
game_mode, hiscore = await pyosrs.get_game_mode("username")
Handling Errors
If the username provided is invalid, a InvalidUserException exception will be raised. If there is a new type of hiscore data response that hasn't been accounted for, a InvalidAPIResponseException exception will be raised.
try:
hiscore = await pyosrs.get_hiscore("invalid username")
except InvalidUserException:
print("Invalid username")
Contributing
If you would like to contribute to pyosrs, please feel free to submit a pull request or open an issue on the GitHub repository.
Here's a quick start guide to setup the project:
git clone https://github.com/phongse/pyosrs.git
cd pyosrs
# Create virtual environment
python -m venv .venv
# Activate venv (Linux, Mac)
source .venv/bin/activate
# Activate venv (Windows)
.\venv\Scripts\Activate.ps1
# Install poetry and pyosrs dependencies
python -m pip install --upgrade pip poetry
poetry install --with dev
# Install pre-commit
pre-commit install
With make you can run tests and format the code:
make format
make mypy
make tests
make precommit
License
pyosrs is licensed under the GNU Lesser General Public License. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyosrs-0.0.8.tar.gz.
File metadata
- Download URL: pyosrs-0.0.8.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1019-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
044921c456ab4a4b4ec1f914ecf68953f0d7e9777ffd8af6d9a4fd2570f16bb8
|
|
| MD5 |
293dc18bc210ffd8498bca9a5fb17968
|
|
| BLAKE2b-256 |
60d0d39de6f8aef31e3660e05b549ec68967132c4b1b5ba4d94ab05f1e13147e
|
File details
Details for the file pyosrs-0.0.8-py3-none-any.whl.
File metadata
- Download URL: pyosrs-0.0.8-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1019-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f32b36d14b4e4e4c3c42b8ec458c5dffb02abb1fb4bbfd3bc1cd7429fc7ae5d
|
|
| MD5 |
cb9a8f8b57edd2cca880b3a3a78a12c8
|
|
| BLAKE2b-256 |
338392c00dfe0079a4831b1d190ea50c40e76186b69d56a417f390960d59d11d
|