Skip to content

Commit 436d39b

Browse files
committed
Handled case for characters with too many deaths
1 parent 8bf6252 commit 436d39b

File tree

6 files changed

+59
-2
lines changed

6 files changed

+59
-2
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Changelog
66
Due to this library relying on external content, older versions are not guaranteed to work.
77
Try to always use the latest version.
88

9+
.. _v2.4.3:
10+
11+
2.4.3 (2020-04-22)
12+
==================
13+
- Fixed an error when trying to parse a character with more deaths than what can be displayed in Tibia.com
14+
- ``Character.deaths_truncated`` field was added to keep track of this case.
15+
916
.. _v2.4.2:
1017

1118
2.4.2 (2020-02-26)

serve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ async def middleware_handler(request):
144144

145145

146146
async def init_client(app):
147-
app["tibiapy"] = tibiapy.Client(proxy_url='socks5://127.0.0.1:7744')
147+
app["tibiapy"] = tibiapy.Client()
148148

149149
if __name__ == "__main__":
150150
app = web.Application(middlewares=[error_middleware])

tests/resources/character/tibiacom_truncated_deaths.txt

Lines changed: 31 additions & 0 deletions
Large diffs are not rendered by default.

tests/tests_character.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
FILE_CHARACTER_TITLE_BADGES = "character/tibiacom_title_badges.txt"
1717
FILE_CHARACTER_NO_BADGES_SELECTED = "character/tibiacom_no_badges_selected.txt"
1818
FILE_CHARACTER_MULTIPLE_HOUSES = "character/tibiacom_multiple_houses.txt"
19+
FILE_CHARACTER_TRUNCATED_DEATHS = "character/tibiacom_truncated_deaths.txt"
1920

2021
FILE_CHARACTER_TIBIADATA = "character/tibiadata.json"
2122
FILE_CHARACTER_TIBIADATA_UNHIDDEN = "character/tibiadata_unhidden.json"
@@ -143,6 +144,14 @@ def test_character_from_content_multiple_houses(self):
143144
self.assertEqual("Edron", first_house.town)
144145
self.assertEqual("Rathleton", second_house.town)
145146

147+
def test_character_from_content_truncated_deaths(self):
148+
"""Testing parsing a character with truncated daths"""
149+
content = self._load_resource(FILE_CHARACTER_TRUNCATED_DEATHS)
150+
char = Character.from_content(content)
151+
self.assertEqual("Godlike Terror", char.name)
152+
self.assertEqual(51, len(char.deaths))
153+
self.assertTrue(char.deaths_truncated)
154+
146155
def test_character_from_content_unrelated(self):
147156
"""Testing parsing an unrelated tibia.com section"""
148157
content = self._load_resource(self.FILE_UNRELATED_SECTION)

tibiapy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from tibiapy.creature import *
1414
from tibiapy.client import *
1515

16-
__version__ = '2.4.2'
16+
__version__ = '2.4.3'
1717

1818
from logging import NullHandler
1919

tibiapy/character.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,15 @@ class Character(abc.BaseCharacter):
178178
The achievements chosen to be displayed.
179179
deaths: :class:`list` of :class:`Death`
180180
The character's recent deaths.
181+
deaths_truncated: :class:`bool`
182+
Whether the character's deaths are truncated or not.
183+
184+
In some cases, there are more deaths in the last 30 days than what can be displayed.
181185
account_information: :class:`AccountInformation`, optional
182186
The character's account information, if visible.
183187
other_characters: :class:`list` of :class:`OtherCharacter`
184188
Other characters in the same account.
189+
185190
It will be empty if the character is hidden, otherwise, it will contain at least the character itself.
186191
"""
187192
__slots__ = (
@@ -205,6 +210,7 @@ class Character(abc.BaseCharacter):
205210
"account_badges",
206211
"achievements",
207212
"deaths",
213+
"deaths_truncated",
208214
"account_information",
209215
"other_characters",
210216
"deletion_date",
@@ -232,6 +238,7 @@ def __init__(self, name=None, world=None, vocation=None, level=0, sex=None, **kw
232238
self.account_badges = kwargs.get("account_badges", []) # type: List[AccountBadge]
233239
self.achievements = kwargs.get("achievements", []) # type: List[Achievement]
234240
self.deaths = kwargs.get("deaths", []) # type: List[Death]
241+
self.deaths_truncated = kwargs.get("deaths", False) # type: bool
235242
self.account_information = kwargs.get("account_information") # type: Optional[AccountInformation]
236243
self.other_characters = kwargs.get("other_characters", []) # type: List[OtherCharacter]
237244
self.deletion_date = try_datetime(kwargs.get("deletion_date"))
@@ -547,6 +554,9 @@ def _parse_deaths(self, rows):
547554
"""
548555
for row in rows:
549556
cols = row.find_all('td')
557+
if len(cols) != 2:
558+
self.deaths_truncated = True
559+
break
550560
death_time_str = cols[0].text.replace("\xa0", " ").strip()
551561
death_time = parse_tibia_datetime(death_time_str)
552562
death = str(cols[1]).replace("\xa0", " ")

0 commit comments

Comments
 (0)