Tibia.py¶
Tibia.py is a libray for parsing HTML content from Tibia.com. into python objects.
This library only performs parsing, to fetch content you need to use external libraries.
import aiohttp
import requests
import tibiapy
# Asynchronously
async def get_character(name):
url = tibiapy.Character.get_url(name)
try:
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
content = await resp.text()
character = tibiapy.Character.from_content(content)
return character
# Synchronously
def get_character_sync(name):
url = tibiapy.Character.get_url(name)
r = requests.get(url)
content = r.text()
character = tibiapy.Character.from_content(content)
return character
Indices and tables¶
Classes¶
Character¶
-
class
tibiapy.
Character
(name=None, world=None, vocation=None, level=0, sex=None, **kwargs)[source]¶ Represents a Tibia character
-
deletion_date
¶ Optional[
datetime.datetime
] – The date where the character will be deleted if it is scheduled for deletion.
-
guild_membership
¶ Optional[
dict
] – The guild the character is a member of. The dictionary contains a key for the rank and a key for the name.
-
last_login
¶ Optional[
datetime.datetime
] – The last time the character logged in. It will be None if the character has never logged in.
-
other_characters
¶ List[
OtherCharacter
] – Other characters in the same account, if visible.
-
static
get_url
(name)[source]¶ Gets the Tibia.com URl for a given character name.
Parameters: name (str) – The name of the character Returns: The URL to the character’s page Return type: str
-
static
from_content
(content) → Optional[tibiapy.character.Character][source]¶ Creates an instance of the class from the html content of the character’s page.
Parameters: content ( str
) – The HTML content of the page.Returns: The character contained in the page, or None if the character doesn’t exist. Return type: Optional[ Character
]
-
Death¶
Guild¶
-
class
tibiapy.
Guild
(name=None, world=None, **kwargs)[source]¶ Represents a Tibia guild.
-
founded
¶ datetime.date
– The day the guild was founded.
-
disband_date
¶ Optional[
str
] – The date when the guild will be disbanded if the condition hasn’t been meet.
-
members
¶ List[
GuildMember
] – List of guild members.
-
invites
¶ List[
GuildInvite
] – List of invited characters.
-
online_members
¶ List[
GuildMember
] – List of currently online members.
-
static
list_from_content
(content, active_only=False)[source]¶ Gets a list of guilds from the html content of the world guilds’ page.
The
Guild
objects in the list only contain the attributes:name
,logo_url
,world
and if available,description
Parameters: Returns: List of guilds in the current world.
Return type: List[
Guild
]
-
static
from_content
(content) → Optional[tibiapy.guild.Guild][source]¶ Creates an instance of the class from the html content of the guild’s page.
Parameters: content ( str
) – The HTML content of the page.Returns: The guild contained in the page or None if it doesn’t exist. Return type: Optional[ Guild
]
-
static
get_url
(name)[source]¶ Gets the Tibia.com URL for a given guild name.
Parameters: name ( str
) – The name of the guildReturns: The URL to the guild’s page Return type: str
-
static
get_world_list_url
(world)[source]¶ Gets the Tibia.com URL for the guild section of a specific world.
Parameters: world ( str
) – The name of the worldReturns: The URL to the guild’s page Return type: str
-
Auxiliary Classes¶
Guild Invite¶
Guild Member¶
-
class
tibiapy.
GuildMember
(name=None, rank=None, title=None, level=0, vocation=None, joined=None, online=False)[source]¶ Represents a guild member.
-
joined
¶ datetime.date
– The day the member joined the guild.
-
Killer¶
Utility functions¶
-
tibiapy.utils.
parse_tibia_datetime
(datetime_str)[source]¶ Parses date and time from the format used in Tibia.com
Parameters: datetime_str (str) – The date and time as represented in Tibia.com Returns: The represented datetime, in UTC. Return type: datetime.datetime
-
tibiapy.utils.
parse_tibia_date
(date_str)[source]¶ Parses a date from the format used in Tibia.com
Parameters: date_str (str) – The date as represented in Tibia.com Returns: The represended date. Return type: datetime.date
Exceptions¶
-
exception
tibiapy.
TibiapyException
[source]¶ Base exception for the tibiapy module.
All exceptions thrown by the module are inherited from this.
-
exception
tibiapy.
InvalidContent
[source]¶ Exception thrown when the parsing couldn’t be completed due to invalid content supplied.
This usually means that the content provided belongs to a different website or section.
In some cases this can mean that Tibia.com’s format has changed and the library needs updating.