Skip to content

Commit 54b657a

Browse files
author
extreme4all
committed
added perf_counter option for hiscore
1 parent 0f10f5e commit 54b657a

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

osrs/asyncio/osrs/hiscores.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import time
23
from enum import Enum
34

45
from aiohttp import ClientSession
@@ -54,7 +55,8 @@ async def get(
5455
player: str,
5556
mode: Mode = Mode.OLDSCHOOL,
5657
session: ClientSession | None = None,
57-
) -> PlayerStats:
58+
return_latency: bool = False,
59+
) -> PlayerStats | tuple[PlayerStats, float]:
5860
"""
5961
Fetches player stats from the OSRS hiscores API.
6062
@@ -74,6 +76,8 @@ async def get(
7476
"""
7577
await self.rate_limiter.check()
7678

79+
start_time = time.perf_counter()
80+
7781
logger.debug(f"Performing hiscores lookup on {player}")
7882
url = f"{self.BASE_URL}/m={mode.value}/index_lite.json"
7983
params = {"player": player}
@@ -99,4 +103,8 @@ async def get(
99103
if session is None:
100104
await _session.close()
101105

106+
if return_latency:
107+
total_time = time.perf_counter() - start_time
108+
return PlayerStats(**data), total_time
109+
102110
return PlayerStats(**data)

osrs/utils/ratelimiter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ async def check(self):
2626
# If time_span is less than interval seconds, sleep for the remaining time
2727
if time_span < self.interval:
2828
sleep_time = self.interval - time_span
29-
logger.debug(f"Rate limit reached. Sleeping for {sleep_time} seconds.")
29+
logger.info(f"Rate limit reached. Sleeping for {sleep_time} seconds.")
3030
await asyncio.sleep(sleep_time)

0 commit comments

Comments
 (0)