The goal is to make a wrapper around the various oldschool runescape api's.
importasynciofromaiohttpimportClientSessionfromosrs.asyncioimportHiscore, HSModefromosrs.utilsimportRateLimiterfromosrs.exceptionsimportPlayerDoesNotExistasyncdefmain():
# 100 calls per minutelimiter=RateLimiter(calls_per_interval=100, interval=60)
hiscore_instance=Hiscore(proxy="", rate_limiter=limiter)
asyncwithClientSession() assession:
player_stats=awaithiscore_instance.get(
mode=HSMode.OLDSCHOOL,
player="extreme4all",
session=session,
)
print(player_stats)
# if you do not provide a session we'll make one for you, this session will not be reused# for multiple requests we advice doing that within one session like the example aboveplayer_stats=awaithiscore_instance.get(
mode=HSMode.OLDSCHOOL,
player="extreme4all",
)
print(player_stats)
# Run the asynchronous main functionif__name__=="__main__":
asyncio.run(main())importasynciofromaiohttpimportClientSessionfromosrs.asyncioimportItemDBMode, Catalogue, Graphfromosrs.utilsimportRateLimiterasyncdefmain():
# Initialize the Catalogue with optional proxy and rate limiterlimiter=RateLimiter(calls_per_interval=100, interval=60)
catalogue_instance=Catalogue(proxy="", rate_limiter=limiter)
graph_instance=Graph(proxy="", rate_limiter=limiter)
asyncwithClientSession() assession:
# Example 1: Fetching items by alphabetical filteralpha="A"# Items starting with "A"page=1# First page of resultscategory=1# Category identifier, for OSRS there is only 1 categoryitems=awaitcatalogue_instance.get_items(
session, alpha=alpha, page=page, mode=ItemDBMode.OLDSCHOOL, category=category
)
print("Fetched Items:", items)
# Example 2: Fetching detailed information for a specific itemitem_id=4151# Example item ID (Abyssal whip in OSRS)item_detail=awaitcatalogue_instance.get_detail(
session, item_id=item_id, mode=ItemDBMode.OLDSCHOOL
)
print("Item Detail:", item_detail)
# Example 3: Fetching historical trade data (price graph) for a specific itemitem_id=4151# Example item ID (Abyssal whip in OSRS)trade_history=awaitgraph_instance.get_graph(
session, item_id=item_id, mode=ItemDBMode.OLDSCHOOL
)
print("Trade History:", trade_history)
# Run the asynchronous main functionif__name__=="__main__":
asyncio.run(main())the wiki via runelite collects item price, which they expose via an api.
importasynciofromaiohttpimportClientSessionfromosrs.asyncioimportWikiPrices, Intervalfromosrs.utilsimportRateLimiterasyncdefmain():
limiter=RateLimiter(calls_per_interval=100, interval=60)
prices_instance=WikiPrices(user_agent="Your User Agent", rate_limiter=limiter)
asyncwithClientSession() assession:
# Fetch item mappingsmappings=awaitprices_instance.get_mapping(
session=session
)
print("Item Mappings:", mappings)
# Fetch latest priceslatest_prices=awaitprices_instance.get_latest_prices(
session=session
)
print("Latest Prices:", latest_prices)
# Fetch average pricesaverage_prices=awaitprices_instance.get_average_prices(
session=session, interval=Interval.FIVE_MIN
)
print("Average Prices:", average_prices)
# Fetch time series dataitem_id=4151# Example item ID (Abyssal whip in OSRS)time_series=awaitprices_instance.get_time_series(
session=session, item_id=item_id, timestep=Interval.ONE_HOUR
)
print("Time Series Data:", time_series)
# Run the asynchronous main functionif__name__=="__main__":
asyncio.run(main())