Skip to content

Commit deccc4d

Browse files
committed
Merge branch 'master' into dev
2 parents 40d9c85 + 78b1b07 commit deccc4d

File tree

7 files changed

+60
-2
lines changed

7 files changed

+60
-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/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ deaths by summons, players, assisted deaths, etcetera.
1212
- [tibiacom_title_badges.txt](character/tibiacom_title_badges.txt) - A character with unlocked titles and badges.
1313
- [tibiacom_no_badges_selected.txt](character/tibiacom_no_badges_selected.txt) - A character with no selected badges.
1414
- [tibiacom_multiple_houses.txt](character/tibiacom_multiple_houses.txt) - A character with two houses.
15+
- [tibiacom_truncated_deaths.txt](character/tibiacom_truncated_deaths.txt) - A character with too many deaths to be displayed.
1516
- [tibiadata.json](character/tibiadata.json) - A character on TibiaData, also showing Pvp deaths with assists.
1617
- [tibiadata_deleted.json](character/tibiadata_deleted.json) - A character scheduled for deletion on TibiaData.
1718
- [tibiadata_not_found.json](character/tibiadata_not_found.json) - The response of a character not found on TibiaData.

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
@@ -14,7 +14,7 @@
1414
from tibiapy.tournament import *
1515
from tibiapy.client import *
1616

17-
__version__ = '2.4.2'
17+
__version__ = '2.4.3'
1818

1919
from logging import NullHandler
2020

tibiapy/character.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,15 @@ class Character(abc.BaseCharacter):
177177
The achievements chosen to be displayed.
178178
deaths: :class:`list` of :class:`Death`
179179
The character's recent deaths.
180+
deaths_truncated: :class:`bool`
181+
Whether the character's deaths are truncated or not.
182+
183+
In some cases, there are more deaths in the last 30 days than what can be displayed.
180184
account_information: :class:`AccountInformation`, optional
181185
The character's account information, if visible.
182186
other_characters: :class:`list` of :class:`OtherCharacter`
183187
Other characters in the same account.
188+
184189
It will be empty if the character is hidden, otherwise, it will contain at least the character itself.
185190
"""
186191
__slots__ = (
@@ -204,6 +209,7 @@ class Character(abc.BaseCharacter):
204209
"account_badges",
205210
"achievements",
206211
"deaths",
212+
"deaths_truncated",
207213
"account_information",
208214
"other_characters",
209215
"deletion_date",
@@ -231,6 +237,7 @@ def __init__(self, name=None, world=None, vocation=None, level=0, sex=None, **kw
231237
self.account_badges = kwargs.get("account_badges", []) # type: List[AccountBadge]
232238
self.achievements = kwargs.get("achievements", []) # type: List[Achievement]
233239
self.deaths = kwargs.get("deaths", []) # type: List[Death]
240+
self.deaths_truncated = kwargs.get("deaths", False) # type: bool
234241
self.account_information = kwargs.get("account_information") # type: Optional[AccountInformation]
235242
self.other_characters = kwargs.get("other_characters", []) # type: List[OtherCharacter]
236243
self.deletion_date = try_datetime(kwargs.get("deletion_date"))
@@ -546,6 +553,9 @@ def _parse_deaths(self, rows):
546553
"""
547554
for row in rows:
548555
cols = row.find_all('td')
556+
if len(cols) != 2:
557+
self.deaths_truncated = True
558+
break
549559
death_time_str = cols[0].text.replace("\xa0", " ").strip()
550560
death_time = parse_tibia_datetime(death_time_str)
551561
death = str(cols[1]).replace("\xa0", " ")

0 commit comments

Comments
 (0)