Galarzaa90/tibia.py

'Client' object has no attribute 'fetch_world_list'

Closed this issue · 1 comments

Hello,
im trying to understand how to use your parser library, with success i can make use of Client.fetch_world but not Client.fetch_world_list

+----------------------------------+--------------------------------------------+----------------------------------------------+
| Worlds_ (Individual) | :meth:World.from_content | :meth:Client.fetch_world |
+----------------------------------+--------------------------------------------+----------------------------------------------+
| Worlds_ (List) | :meth:WorldOverview.from_content | :meth:Client.fetch_world_list |
+----------------------------------+--------------------------------------------+----------------------------------------------+

import aiohttp
import tibiapy

async def fetch_world_list():
    headers = {
        "Cache-Control": "no-store, max-age=0"
    }
    async with aiohttp.ClientSession(headers=headers) as session:
        try:
            world_list_response = await tibiapy.Client(session=session).fetch_world_list()
            if world_list_response.data:
                return world_list_response.data.worlds
        except tibiapy.Forbidden:
            print("403 Forbidden.")
        except tibiapy.NetworkError:
            print("Connection error.")
    return []

async def main():
    worlds = await fetch_world_list()
    if worlds:
        for world in worlds:
            print(f"World Name: {world.name}, Players Online: {world.online_count}")

if __name__ == "__main__":
    asyncio.run(main())

I completely overlooked the examples and the supported sections table. I have updated it now.