Skip to content

Commit da069d0

Browse files
committed
Fixed error on character parsing when character has no badges selected
1 parent e78b55a commit da069d0

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ 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.2.6:
10+
11+
2.2.6 (2019-09-01)
12+
==================
13+
- Fixed bug with account badges parsing failing when no badges were selected.
14+
915
.. _v2.2.5:
1016

1117
2.2.5 (2019-08-22)

tests/resources/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ deaths by summons, players, assisted deaths, etcetera.
99
- [tibiacom_former_names.txt](character/tibiacom_former_names.txt) - A character with former names.
1010
- [tibiacom_full.txt](character/tibiacom_full.txt) - A full character response.
1111
- [tibiacom_not_found.txt](character/tibiacom_not_found.txt) - A character not found page.
12-
- [tibiacom_title_badges.txt](character/tibiacom_title_badges.txt) - A character not found page.
12+
- [tibiacom_title_badges.txt](character/tibiacom_title_badges.txt) - A character with unlocked titles and badges.
13+
- [tibiacom_no_badges_selected.txt](character/tibiacom_no_badges_selected.txt) - A character with no selected badges.
1314
- [tibiadata.json](character/tibiadata.json) - A character on TibiaData, also showing Pvp deaths with assists.
1415
- [tibiadata_deleted.json](character/tibiadata_deleted.json) - A character scheduled for deletion on TibiaData.
1516
- [tibiadata_not_found.json](character/tibiadata_not_found.json) - The response of a character not found on TibiaData.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div class="BoxContent" style="background-image:url(https://static.tibia.com/images/global/content/scroll.gif);">
2+
<table border="0" cellspacing="1" cellpadding="4" width="100%"><tr bgcolor=#505050><td colspan=2 class=white><b>Character Information</b></td></tr><tr bgcolor=#F1E0C6><td width=20%>Name:</td><td>Cozzackirycerz <div style="float: right"></div></td></tr><tr bgcolor=#D4C0A1><td>Title:</td><td>None (3 titles unlocked)</td></tr><tr bgcolor=#F1E0C6><td>Sex:</td><td>male</td></tr><tr bgcolor=#D4C0A1><td>Vocation:</td><td>Elite Knight</td></tr><tr bgcolor=#F1E0C6><td>Level:</td><td>84</td></tr><tr bgcolor=#D4C0A1><td><nobr>Achievement Points:</nobr></td><td>25</td></tr><tr bgcolor=#F1E0C6><td>World:</td><td>Antica</td></tr><tr bgcolor=#D4C0A1><td>Residence:</td><td>Yalahar</td></tr><tr bgcolor=#F1E0C6><td>Last Login:</td><td>Sep&#160;01&#160;2019,&#160;13:44:28&#160;CEST</td></tr><tr bgcolor=#D4C0A1><td>Account&#160;Status:</td><td>Premium Account</td></tr></table>
3+
<br /><br /><table border="0" cellspacing="1" cellpadding="4" width="100%"><tr bgcolor="#505050"><td colspan="100%" class="white"><b>Account Badges</b></td></tr><tr bgcolor="#F1E0C6"><td colspan="100%">There are no account badges set to be displayed for this character.</td></tr></table><br /><br /><table border="0" cellspacing="1" cellpadding="4" width="100%"><tr bgcolor="#505050"><td colspan="2" class="white"><b>Account Achievements</b></td></tr><tr bgcolor="#F1E0C6"><td colspan="2">There are no achievements set to be displayed for this character.</td></tr></table><br /><br /><table border="0" cellspacing="1" cellpadding="4" width="100%"><tr bgcolor="#505050"><td colspan="2" class="white"><b>Character Deaths</b></td></tr><tr bgcolor="#F1E0C6"><td width="25%" valign="top">Aug&#160;04&#160;2019,&#160;21:22:23&#160;CEST</td><td>Slain at Level 84 by <a href="https://www.tibia.com/community/?subtopic=characters&name=Sheva+La+Bonita">Sheva&#160;La&#160;Bonita</a>, <a href="https://www.tibia.com/community/?subtopic=characters&name=Horhe+Em+Divine">Horhe&#160;Em&#160;Divine</a>, <a href="https://www.tibia.com/community/?subtopic=characters&name=Salyok+Le">Salyok&#160;Le</a>, <a href="https://www.tibia.com/community/?subtopic=characters&name=Snorrunge">Snorrunge</a> and <a href="https://www.tibia.com/community/?subtopic=characters&name=Cozzackirycerz">Cozzackirycerz</a>.</td></tr><tr bgcolor="#D4C0A1"><td width="25%" valign="top">Aug&#160;03&#160;2019,&#160;04:17:00&#160;CEST</td><td>Killed at Level 83 by <a href="https://www.tibia.com/community/?subtopic=characters&name=Ova+Inferno">Ova&#160;Inferno</a> and <a href="https://www.tibia.com/community/?subtopic=characters&name=Shooter+Here">Shooter&#160;Here</a>.</td></tr></table><br /><br /> <FORM ACTION="https://www.tibia.com/community/?subtopic=characters" METHOD=post>
4+
<TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4>
5+
<TR><TD BGCOLOR="#505050" CLASS=white><B>Search Character</B></TD></TR>
6+
<TR><TD BGCOLOR="#D4C0A1"><TABLE BORDER=0 CELLPADDING=1><TR>
7+
<TD>Name:</TD><TD><INPUT NAME="name" VALUE="Cozzackirycerz" SIZE=29 MAXLENGTH=29></TD>
8+
<TD><INPUT TYPE=image NAME="Submit" SRC="https://static.tibia.com/images/global/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18></TD>
9+
</TR></TABLE></TD></TR>

tests/tests_character.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
FILE_CHARACTER_DELETION = "character/tibiacom_deletion.txt"
1515
FILE_CHARACTER_DEATHS_COMPLEX = "character/tibiacom_deaths_complex.txt"
1616
FILE_CHARACTER_TITLE_BADGES = "character/tibiacom_title_badges.txt"
17+
FILE_CHARACTER_NO_BADGES_SELECTED = "character/tibiacom_no_badges_selected.txt"
1718

1819
FILE_CHARACTER_TIBIADATA = "character/tibiadata.json"
1920
FILE_CHARACTER_TIBIADATA_UNHIDDEN = "character/tibiadata_unhidden.json"
@@ -116,6 +117,17 @@ def test_character_from_content_badges_and_title(self):
116117
self.assertIsInstance(badge.icon_url, str)
117118
self.assertIsInstance(badge.description, str)
118119

120+
def test_character_from_content_no_selected_badges(self):
121+
"""Testing parsing a character with visible badges but none selected."""
122+
content = self._load_resource(FILE_CHARACTER_NO_BADGES_SELECTED)
123+
char = Character.from_content(content)
124+
self.assertEqual("Cozzackirycerz", char.name)
125+
self.assertEqual(25, char.achievement_points)
126+
self.assertIsNone(char.title)
127+
self.assertEqual(3, char.unlocked_titles)
128+
self.assertEqual(0, len(char.account_badges))
129+
self.assertEqual(0, len(char.former_names))
130+
119131
def test_character_from_content_unrelated(self):
120132
"""Testing parsing an unrelated tibia.com section"""
121133
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.2.5'
16+
__version__ = '2.2.6'
1717

1818
from logging import NullHandler
1919

tibiapy/character.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ def _parse_badges(self, rows):
435435
columns = row.find_all('td')
436436
for column in columns:
437437
popup = column.find("span", attrs={"class": "HelperDivIndicator"})
438+
if not popup:
439+
# Badges are visible, but none selected.
440+
return
438441
m = badge_popup_regexp.search(popup['onmouseover'])
439442
if m:
440443
name = m.group(1)

0 commit comments

Comments
 (0)