From 84ffc0c141d42bd2ca2ad5ab8aa3b5498b2eddda Mon Sep 17 00:00:00 2001 From: extreme4all <40169115+extreme4all@users.noreply.github.com> Date: Sun, 27 Oct 2024 00:58:15 +0200 Subject: [PATCH] minor fixes --- README.md | 92 ++++++++------------------------- notes.md | 27 ---------- osrs/async_api/osrs/hiscores.py | 2 + osrs/utils/.gitkeep | 0 osrs/utils/ratelimiter.py | 6 +-- pyproject.toml | 2 +- 6 files changed, 28 insertions(+), 101 deletions(-) delete mode 100644 notes.md delete mode 100644 osrs/utils/.gitkeep diff --git a/README.md b/README.md index d1c9fd6..fbe94c7 100644 --- a/README.md +++ b/README.md @@ -1,78 +1,30 @@ # The project -The goal is to make a wrapper around the varius runescape related api's. +The goal is to make a wrapper around the various oldschool runescape api's. -# Runelite -## prices -Runelite prices api: https://prices.runescape.wiki/api/v1/osrs/ -you must provide some identification to tell who you are, preferably with a discord tag or email -``` -from osrs import runelite +# osrs hiscores +```py +import asyncio -api = runelite.RunelitePrices(identification='extreme4all#6455') -``` -to get a mapping of item names, id, low & high alch values etc -``` -print(api.items()) -``` -to get latest prices averaging over an interval or from a specific timestamp -``` -intervals = [ - '5m', - '10m', - '30m', - '1h', - '6h', - '24h' -] -print(api.prices(interval='24h')) -print(api.prices(interval='24h', timestamp=1628380800)) -``` -to get a timeseries of the 300 values averaged over interval by item id or item name -``` -print(api.timeseries(interval='5m', id=2)) -print(api.timeseries(interval='5m', name='Cannonball')) -``` +from aiohttp import ClientSession -to get the latest prices of items -``` -print(api.latest()) -``` -# OSRS -The osrs endpoints, these endpoints are heavily rate limited -## osrsPrices -``` -from osrs import osrs +from osrs.async_api.osrs.hiscores import Mode, PlayerStats, Hiscore, RateLimiter +from osrs.exceptions import PlayerDoesNotExist -api = osrs.OsrsPrices(identification='extreme4all#6456') -``` -OSRS has only one category, with all the items, here you get each alpha or letter and howmany items are in it -``` -print(api.category()) -``` -The items endpoint is paginated and will return 12 items for each page -``` -print(api.items(letter='a', page=0)) -``` -You can get the itemDetails for a specific item, based on item_id -``` -print(api.itemDetail(item_id=4151)) -``` -You can get the item price as a timeseries based on item_id -``` -print(api.timeseries(item_id=4151)) -``` -## hiscores -return the hiscore for a player -``` -from osrs import osrs -api = osrs.Hiscores(identification='extreme4all#6456') -modes = [ - 'hiscore_oldschool', 'hiscore_oldschool_ironman', 'hiscore_oldschool_hardcore_ironman', - 'hiscore_oldschool_ultimate','hiscore_oldschool_deadman','hiscore_oldschool_seasonal', - 'hiscore_oldschool_tournament' -] +async def main(): + # 100 calls per minute + limiter = RateLimiter(calls_per_interval=100, interval=60) + hiscore_instance = Hiscore(proxy="", rate_limiter=limiter) -print(api.player(player_name='extreme4all', mode='hiscore_oldschool')) -``` + async with ClientSession() as session: + player_stats = await hiscore_instance.get( + mode=Mode.OLDSCHOOL, + player="extreme4all", + session=session, + ) + print(player_stats) + +loop = asyncio.get_running_loop() +await loop.create_task(main()) +``` \ No newline at end of file diff --git a/notes.md b/notes.md deleted file mode 100644 index adc28b9..0000000 --- a/notes.md +++ /dev/null @@ -1,27 +0,0 @@ -# development -## setup -``` -python -m venv .venv -.venv\Scripts\activate -python -m pip install --upgrade pip -pip install -r requirements.txt -``` -## for admin purposes saving & upgrading - -``` -venv\Scripts\activate -call pip freeze > requirements.txt -powershell "(Get-Content requirements.txt) | ForEach-Object { $_ -replace '==', '>=' } | Set-Content requirements.txt" -call pip install -r requirements.txt --upgrade -call pip freeze > requirements.txt -powershell "(Get-Content requirements.txt) | ForEach-Object { $_ -replace '>=', '==' } | Set-Content requirements.txt" -``` -## build & publish -building package and deploying to pypi -https://packaging.python.org/en/latest/tutorials/packaging-projects/ -``` -python -m pip install --upgrade build -python -m build -python -m pip install --upgrade twine -twine upload dist/* -``` \ No newline at end of file diff --git a/osrs/async_api/osrs/hiscores.py b/osrs/async_api/osrs/hiscores.py index e7bc9c5..dbe4f3e 100644 --- a/osrs/async_api/osrs/hiscores.py +++ b/osrs/async_api/osrs/hiscores.py @@ -67,6 +67,8 @@ async def get(self, mode: Mode, player: str, session: ClientSession) -> PlayerSt ClientResponseError: For other HTTP errors. Undefined: For anything else that is not a 200 """ + await self.rate_limiter.check() + logger.info(f"Performing hiscores lookup on {player}") url = f"{self.BASE_URL}/m={mode.value}/index_lite.json" params = {"player": player} diff --git a/osrs/utils/.gitkeep b/osrs/utils/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/osrs/utils/ratelimiter.py b/osrs/utils/ratelimiter.py index 4d37a1b..e31af10 100644 --- a/osrs/utils/ratelimiter.py +++ b/osrs/utils/ratelimiter.py @@ -7,9 +7,9 @@ class RateLimiter: - def __init__(self, calls_per: int = 60, inteval: int = 60) -> None: - self.history = deque(maxlen=calls_per) - self.interval = inteval + def __init__(self, calls_per_interval: int = 60, interval: int = 60) -> None: + self.history = deque(maxlen=calls_per_interval) + self.interval = interval async def check(self): """ diff --git a/pyproject.toml b/pyproject.toml index 653d3c6..61e475e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "osrs" -version = "0.0.8" +version = "0.0.9" authors = [ { name="extreme4all"}, ]