Skip to content

Commit

Permalink
Properly parse the name of recently traded characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Galarzaa90 committed Aug 27, 2020
1 parent a5d10c6 commit 49022a0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Changelog
Due to this library relying on external content, older versions are not guaranteed to work.
Try to always use the latest version.

.. v3.2.2:
3.2.2 (2020-08-27)
==================

- Properly parse the name of recently traded characters.
- Added ``traded`` attribute to ``Character`` and ``OtherCharacter``.

.. v3.2.1:
3.2.1 (2020-08-25)
Expand Down
2 changes: 1 addition & 1 deletion tibiapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from tibiapy.world import *
from tibiapy.client import *

__version__ = '3.2.1'
__version__ = '3.2.2'

from logging import NullHandler

Expand Down
20 changes: 18 additions & 2 deletions tibiapy/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class Character(abc.BaseCharacter, abc.Serializable):
----------
name: :class:`str`
The name of the character.
traded: :class:`bool`
If the character was traded in the last 6 months.
deletion_date: :class:`datetime.datetime`, optional
The date when the character will be deleted if it is scheduled for deletion.
former_names: :class:`list` of :class:`str`
Expand Down Expand Up @@ -190,6 +192,7 @@ class Character(abc.BaseCharacter, abc.Serializable):
__slots__ = (
"name",
"former_names",
"traded",
"sex",
"title",
"unlocked_titles",
Expand Down Expand Up @@ -222,6 +225,7 @@ class Character(abc.BaseCharacter, abc.Serializable):

def __init__(self, name=None, world=None, vocation=None, level=0, sex=None, **kwargs):
self.name: str = name
self.traded: bool = kwargs.get("traded", False)
self.former_names: List[str] = kwargs.get("former_names", [])
self.title: Optional[str] = kwargs.get("title")
self.unlocked_titles = int(kwargs.get("unlocked_titles", 0))
Expand Down Expand Up @@ -436,6 +440,10 @@ def _parse_character_information(self, rows):
m = guild_regexp.match(char["guild_membership"])
char["guild_membership"] = GuildMembership(m.group(2), m.group(1))

if "(traded)" in char["name"]:
char["name"] = char["name"].replace("(traded)","").strip()
char["traded"] = True

if "former_names" in char:
former_names = [fn.strip() for fn in char["former_names"].split(",")]
char["former_names"] = former_names
Expand Down Expand Up @@ -558,6 +566,10 @@ def _parse_other_characters(self, rows):
name, world, status, *__ = cols
_, *name = name.replace("\xa0", " ").split(" ")
name = " ".join(name)
traded = False
if "(recently traded)" in name:
name = name.replace("(recently traded)", "").strip()
traded = True
main_img = cols_raw[0].find('img')
main = False
if main_img and main_img['title'] == "Main Character":
Expand All @@ -566,7 +578,7 @@ def _parse_other_characters(self, rows):
if "CipSoft Member" in status:
position = "CipSoft Member"
self.other_characters.append(OtherCharacter(name, world, "online" in status, "deleted" in status, main,
position))
position, traded))

@classmethod
def _parse_tables(cls, parsed_content):
Expand Down Expand Up @@ -779,6 +791,8 @@ class OtherCharacter(abc.BaseCharacter, abc.Serializable):
Whether the character is online or not.
deleted: :class:`bool`
Whether the character is scheduled for deletion or not.
traded: :class:`bool`
Whether the character has been traded recently or not.
main: :class:`bool`
Whether this is the main character or not.
position: :class:`str`
Expand All @@ -789,16 +803,18 @@ class OtherCharacter(abc.BaseCharacter, abc.Serializable):
"world",
"online",
"deleted",
"traded",
"main",
"position",
)

def __init__(self, name, world, online=False, deleted=False, main=False, position=None):
def __init__(self, name, world, online=False, deleted=False, main=False, position=None, traded=False):
self.name: str = name
self.world: str = world
self.online: bool = online
self.deleted: bool = deleted
self.main: bool = main
self.traded: bool = traded
self.position: Optional[str] = position

def __repr__(self):
Expand Down

0 comments on commit 49022a0

Please sign in to comment.