Skip to content

Commit 6d69a14

Browse files
committed
Fixed spell parsing due to tibia.com changes
1 parent 55a498f commit 6d69a14

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

tests/resources/library/spell_list_default.txt

Lines changed: 5 additions & 6 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<div class="BoxContent" style="background-image:url(https://static.tibia.com/images/global/content/scroll.gif);">
2-
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR><TD><IMG SRC="https://static.tibia.com/images/library/chameleonrune.png" WIDTH="32" HEIGHT="32" /></TD><TD WIDTH=90%><CENTER><H2>Chameleon Rune</H2></CENTER></TD><TD><IMG SRC="https://static.tibia.com/images/library/chameleonrune.png" WIDTH="32" HEIGHT="32" /></TD></TR></TABLE><BR>This peculiar rune spell was more or less discovered by accident. Legend has it that the famous druid Ferdo the Forgetful tested a new healing spell on himself to cure his toothache, only to find that he was turned into a flowerpot! However, the metamorphosis caused by Chameleon is only superficial, and while a caster who is using the spell can take on the exterior form of nearly any inanimate object, he will always retain his original smell and mental abilities. While this proved to be good luck for Ferdo, it clearly showed the spell's limitations. Very few creatures and only the most distracted of intelligent beings are fooled by Chameleon, so there is no practical use for it, making this largely a fun spell. However, some of the foremost of today's druids are still researching the spell, so it is to be hoped that one day the spell's evident flaws can be removed.<BR><BR><BR><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR=#505050><TD COLSPAN=2 CLASS=white><B>Spell Information</B></TD></TR><TR BGCOLOR=#F1E0C6><TD WIDTH=15%>Name:</TD><TD>Chameleon Rune</TD></TR><TR BGCOLOR=#D4C0A1><TD WIDTH=15%>Formula:</TD><TD>adevo ina</TD></TR><TR BGCOLOR=#F1E0C6><TD>Vocation:</TD><TD>Druid</TD></TR><TR BGCOLOR=#D4C0A1><TD>Group:</TD><TD>Support</TD></TR><TR BGCOLOR=#F1E0C6><TD>Type:</TD><TD>Rune</TD></TR><TR BGCOLOR=#D4C0A1><TD WIDTH=15%>Cooldown:</TD><TD>2s (Group: 2s)</TD></TR><TR BGCOLOR=#F1E0C6><TD>Soul Points:</TD><TD>2</TD></TR><TR BGCOLOR=#D4C0A1><TD>Amount:</TD><TD>1</TD></TR><TR BGCOLOR=#F1E0C6><TD>Exp Lvl:</TD><TD>27</TD></TR><TR BGCOLOR=#D4C0A1><TD>Mana:</TD><TD>600</TD></TR><TR BGCOLOR=#F1E0C6><TD>Price:</TD><TD>1300</TD></TR><TR BGCOLOR=#D4C0A1><TD>City:</TD><TD>Ab'Dendriel, Ankrahmun, Carlin, Darashia, Edron, Issavi, Liberty Bay, Port Hope, Svargrond, Thais, Venore, Yalahar</TD></TR><TR BGCOLOR=#F1E0C6><TD>Premium:</TD><TD>no</TD></TR></TABLE><BR><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR=#505050><TD COLSPAN=2 CLASS=white><B>Rune Information</B></TD></TR><TR BGCOLOR=#D4C0A1><TD WIDTH=15%>Name:</TD><TD>Chameleon Rune</TD></TR><TR BGCOLOR=#F1E0C6><TD>Vocation:</TD><TD>Druid, Knight, Paladin, Sorcerer</TD></TR><TR BGCOLOR=#D4C0A1><TD>Group:</TD><TD>Support</TD></TR><TR BGCOLOR=#F1E0C6><TD>Exp Lvl:</TD><TD>27</TD></TR><TR BGCOLOR=#D4C0A1><TD>Mag Lvl:</TD><TD>4</TD></TR></TABLE><BR><CENTER><form action="https://www.tibia.com/library/?subtopic=spells" method="post" style="padding:0px;margin:0px;"><input type="hidden" name="vocation" value="" /><input type="hidden" name="group" value="" /><input type="hidden" name="type" value="" /><input type="hidden" name="premium" value="" /><input type="hidden" name="sort" value="" /><div class="BigButton" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue.gif)"><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);"><div class="BigButtonOver" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue_over.gif);"></div><input class="BigButtonText" type="submit" value="Back" /></div></div></form></CENTER> </div>
2+
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR><TD><IMG SRC="https://static.tibia.com/images/library/chameleonrune.png" WIDTH="32" HEIGHT="32" /></TD><TD WIDTH=90%><CENTER><H2>Chameleon Rune</H2></CENTER></TD><TD><IMG SRC="https://static.tibia.com/images/library/chameleonrune.png" WIDTH="32" HEIGHT="32" /></TD></TR></TABLE><BR>This peculiar rune spell was more or less discovered by accident. Legend has it that the famous druid Ferdo the Forgetful tested a new healing spell on himself to cure his toothache, only to find that he was turned into a flowerpot! However, the metamorphosis caused by Chameleon is only superficial, and while a caster who is using the spell can take on the exterior form of nearly any inanimate object, he will always retain his original smell and mental abilities. While this proved to be good luck for Ferdo, it clearly showed the spell's limitations. Very few creatures and only the most distracted of intelligent beings are fooled by Chameleon, so there is no practical use for it, making this largely a fun spell. However, some of the foremost of today's druids are still researching the spell, so it is to be hoped that one day the spell's evident flaws can be removed.<BR><BR><BR><div class="TableContainer"> <table class="Table2" cellpadding="0" cellspacing="0"> <div class="CaptionContainer"> <div class="CaptionInnerContainer"> <span class="CaptionEdgeLeftTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionBorderTop" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionVerticalLeft" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <div class="Text">Spell Information</div> <span class="CaptionVerticalRight" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <span class="CaptionBorderBottom" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionEdgeLeftBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> </div> </div> <tr> <td> <div class="InnerTableContainer"> <table style="width:100%;"><tr><td> <div class="TableContentContainer"> <table class="TableContent" width="100%" style="border:1px solid #faf0d7;"><TR BGCOLOR=#D4C0A1><TD WIDTH=15%>Name:</TD><TD>Chameleon Rune</TD></TR><TR BGCOLOR=#F1E0C6><TD WIDTH=15%>Formula:</TD><TD>adevo ina</TD></TR><TR BGCOLOR=#D4C0A1><TD>Vocation:</TD><TD>Druid</TD></TR><TR BGCOLOR=#F1E0C6><TD>Group:</TD><TD>Support</TD></TR><TR BGCOLOR=#D4C0A1><TD>Type:</TD><TD>Rune</TD></TR><TR BGCOLOR=#F1E0C6><TD WIDTH=15%>Cooldown:</TD><TD>2s (Group: 2s)</TD></TR><TR BGCOLOR=#D4C0A1><TD>Soul Points:</TD><TD>2</TD></TR><TR BGCOLOR=#F1E0C6><TD>Amount:</TD><TD>1</TD></TR><TR BGCOLOR=#D4C0A1><TD>Exp Lvl:</TD><TD>27</TD></TR><TR BGCOLOR=#F1E0C6><TD>Mana:</TD><TD>600</TD></TR><TR BGCOLOR=#D4C0A1><TD>Price:</TD><TD>1300</TD></TR><TR BGCOLOR=#F1E0C6><TD>City:</TD><TD>Ab'Dendriel, Ankrahmun, Carlin, Darashia, Edron, Issavi, Liberty Bay, Port Hope, Svargrond, Thais, Venore, Yalahar</TD></TR><TR BGCOLOR=#D4C0A1><TD>Premium:</TD><TD>no</TD></TR> </table> </div></td></tr> </table> </div> </td> </tr> </table></div><BR><div class="TableContainer"> <table class="Table2" cellpadding="0" cellspacing="0"> <div class="CaptionContainer"> <div class="CaptionInnerContainer"> <span class="CaptionEdgeLeftTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionBorderTop" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionVerticalLeft" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <div class="Text">Rune Information</div> <span class="CaptionVerticalRight" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <span class="CaptionBorderBottom" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionEdgeLeftBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> </div> </div> <tr> <td> <div class="InnerTableContainer"> <table style="width:100%;"><tr><td> <div class="TableContentContainer"> <table class="TableContent" width="100%" style="border:1px solid #faf0d7;"><TR BGCOLOR=#D4C0A1><TD WIDTH=15%>Name:</TD><TD>Chameleon Rune</TD></TR><TR BGCOLOR=#F1E0C6><TD>Vocation:</TD><TD>Druid, Knight, Paladin, Sorcerer</TD></TR><TR BGCOLOR=#D4C0A1><TD>Group:</TD><TD>Support</TD></TR><TR BGCOLOR=#F1E0C6><TD>Exp Lvl:</TD><TD>27</TD></TR><TR BGCOLOR=#D4C0A1><TD>Mag Lvl:</TD><TD>4</TD></TR> </table> </div></td></tr> </table> </div> </td> </tr> </table></div><BR><CENTER><form action="https://www.tibia.com/library/?subtopic=spells" method="post" style="padding:0px;margin:0px;"><input type="hidden" name="vocation" value="" /><input type="hidden" name="group" value="" /><input type="hidden" name="type" value="" /><input type="hidden" name="premium" value="" /><input type="hidden" name="sort" value="" /><div class="BigButton" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue.gif)"><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);"><div class="BigButtonOver" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue_over.gif);"></div><input class="BigButtonText" type="submit" value="Back" /></div></div></form></CENTER> </div>
3+
</div>
34
</div>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div class="BoxContent" style="background-image:url(https://static.tibia.com/images/global/content/scroll.gif);">
22
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR><TD><IMG SRC="https://static.tibia.com/images/library/protector.png" WIDTH="32" HEIGHT="32" /></TD><TD WIDTH=90%><CENTER><H2>Protector</H2></CENTER></TD><TD><IMG SRC="https://static.tibia.com/images/library/protector.png" WIDTH="32" HEIGHT="32" /></TD></TR></TABLE><BR>To be able to defend themselves against extremely powerful hits, experienced knights can cast the Protector spell. If cast, the shielding of the knight will raise to 220% and the knight will gain an overall damage reduction of 15% for 10 seconds. However, as the knight needs to concentrate all his energy on this spell, his attacks and spells have a -35% penalty during this time.<BR />
3-
A knight is versatile and can alter quickly between an aggressive stance and a defensive stance by casting Blood Rage to remove Protector.<BR><BR><BR><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR=#505050><TD COLSPAN=2 CLASS=white><B>Spell Information</B></TD></TR><TR BGCOLOR=#F1E0C6><TD WIDTH=15%>Name:</TD><TD>Protector</TD></TR><TR BGCOLOR=#D4C0A1><TD WIDTH=15%>Formula:</TD><TD>utamo tempo</TD></TR><TR BGCOLOR=#F1E0C6><TD>Vocation:</TD><TD>Knight</TD></TR><TR BGCOLOR=#D4C0A1><TD>Group:</TD><TD>Support (Secondary Group: Focus)</TD></TR><TR BGCOLOR=#F1E0C6><TD>Type:</TD><TD>Instant</TD></TR><TR BGCOLOR=#D4C0A1><TD WIDTH=15%>Cooldown:</TD><TD>2s (Group: 2s ,Secondary Group: 2s)</TD></TR><TR BGCOLOR=#F1E0C6><TD>Exp Lvl:</TD><TD>55</TD></TR><TR BGCOLOR=#D4C0A1><TD>Mana:</TD><TD>200</TD></TR><TR BGCOLOR=#F1E0C6><TD>Price:</TD><TD>6000</TD></TR><TR BGCOLOR=#D4C0A1><TD>City:</TD><TD>Edron</TD></TR><TR BGCOLOR=#F1E0C6><TD>Premium:</TD><TD>yes</TD></TR></TABLE><BR><CENTER><form action="https://www.tibia.com/library/?subtopic=spells" method="post" style="padding:0px;margin:0px;"><input type="hidden" name="vocation" value="" /><input type="hidden" name="group" value="" /><input type="hidden" name="type" value="" /><input type="hidden" name="premium" value="" /><input type="hidden" name="sort" value="" /><div class="BigButton" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue.gif)"><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);"><div class="BigButtonOver" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue_over.gif);"></div><input class="BigButtonText" type="submit" value="Back" /></div></div></form></CENTER> </div>
3+
A knight is versatile and can alter quickly between an aggressive stance and a defensive stance by casting Blood Rage to remove Protector.<BR><BR><BR><div class="TableContainer"> <table class="Table2" cellpadding="0" cellspacing="0"> <div class="CaptionContainer"> <div class="CaptionInnerContainer"> <span class="CaptionEdgeLeftTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightTop" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionBorderTop" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionVerticalLeft" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <div class="Text">Spell Information</div> <span class="CaptionVerticalRight" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-vertical.gif);" /></span> <span class="CaptionBorderBottom" style="background-image:url(https://static.tibia.com/images/global/content/table-headline-border.gif);"></span> <span class="CaptionEdgeLeftBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightBottom" style="background-image:url(https://static.tibia.com/images/global/content/box-frame-edge.gif);" /></span> </div> </div> <tr> <td> <div class="InnerTableContainer"> <table style="width:100%;"><tr><td> <div class="TableContentContainer"> <table class="TableContent" width="100%" style="border:1px solid #faf0d7;"><TR BGCOLOR=#D4C0A1><TD WIDTH=15%>Name:</TD><TD>Protector</TD></TR><TR BGCOLOR=#F1E0C6><TD WIDTH=15%>Formula:</TD><TD>utamo tempo</TD></TR><TR BGCOLOR=#D4C0A1><TD>Vocation:</TD><TD>Knight</TD></TR><TR BGCOLOR=#F1E0C6><TD>Group:</TD><TD>Support (Secondary Group: Focus)</TD></TR><TR BGCOLOR=#D4C0A1><TD>Type:</TD><TD>Instant</TD></TR><TR BGCOLOR=#F1E0C6><TD WIDTH=15%>Cooldown:</TD><TD>2s (Group: 2s ,Secondary Group: 2s)</TD></TR><TR BGCOLOR=#D4C0A1><TD>Exp Lvl:</TD><TD>55</TD></TR><TR BGCOLOR=#F1E0C6><TD>Mana:</TD><TD>200</TD></TR><TR BGCOLOR=#D4C0A1><TD>Price:</TD><TD>6000</TD></TR><TR BGCOLOR=#F1E0C6><TD>City:</TD><TD>Edron</TD></TR><TR BGCOLOR=#D4C0A1><TD>Premium:</TD><TD>yes</TD></TR> </table> </div></td></tr> </table> </div> </td> </tr> </table></div><BR><CENTER><form action="https://www.tibia.com/library/?subtopic=spells" method="post" style="padding:0px;margin:0px;"><input type="hidden" name="vocation" value="" /><input type="hidden" name="group" value="" /><input type="hidden" name="type" value="" /><input type="hidden" name="premium" value="" /><input type="hidden" name="sort" value="" /><div class="BigButton" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue.gif)"><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);"><div class="BigButtonOver" style="background-image:url(https://static.tibia.com/images/global/buttons/button_blue_over.gif);"></div><input class="BigButtonText" type="submit" value="Back" /></div></div></form></CENTER> </div>
4+
</div>
45
</div>

tibiapy/spell.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
from tibiapy import abc, errors
1010
from tibiapy.enums import SpellGroup, SpellSorting, SpellType, VocationSpellFilter
11-
from tibiapy.utils import get_tibia_url, parse_form_data, parse_integer, parse_tibiacom_content, try_enum
11+
from tibiapy.utils import get_tibia_url, parse_form_data, parse_integer, parse_tibiacom_content, parse_tibiacom_tables, \
12+
try_enum
1213

1314
__all__ = (
1415
'SpellsSection',
@@ -98,11 +99,14 @@ def from_content(cls, content):
9899
"""
99100
try:
100101
parsed_content = parse_tibiacom_content(content)
101-
spells_table = parsed_content.find("table")
102-
spell_rows = spells_table.find_all("tr")
102+
table_content_container = parsed_content.find("div", attrs={"class": "InnerTableContainer"})
103+
spells_table = table_content_container.find("table", class_=lambda t: t != "TableContent")
104+
spell_rows = spells_table.find_all("tr", {'bgcolor': ["#D4C0A1", "#F1E0C6"]})
103105
spells_section = cls()
104-
for row in spell_rows[1:]:
106+
for row in spell_rows:
105107
columns = row.find_all("td")
108+
if len(columns) != 7:
109+
continue
106110
spell_link = columns[0].find("a")
107111
url = urllib.parse.urlparse(spell_link["href"])
108112
query = urllib.parse.parse_qs(url.query)
@@ -344,9 +348,9 @@ def from_content(cls, content):
344348
"""
345349
parsed_content = parse_tibiacom_content(content)
346350
try:
347-
tables = parsed_content.find_all("table")
348-
title_table = tables[0]
349-
spell_table = tables[1]
351+
tables = parse_tibiacom_tables(parsed_content)
352+
title_table = parsed_content.find("table", attrs={"class": False})
353+
spell_table = tables["Spell Information"]
350354
img = title_table.find("img")
351355
url = urllib.parse.urlparse(img["src"])
352356
filename = os.path.basename(url.path)
@@ -366,10 +370,10 @@ def from_content(cls, content):
366370
next_sibling = next_sibling.next_sibling
367371
spell = cls._parse_spells_table(identifier, spell_table)
368372
spell.description = description.strip()
369-
if len(tables) > 2:
370-
spell.rune = cls._parse_rune_table(tables[2])
373+
if "Rune Information" in tables:
374+
spell.rune = cls._parse_rune_table(tables["Rune Information"])
371375
return spell
372-
except (TypeError, AttributeError, IndexError) as e:
376+
except (TypeError, AttributeError, IndexError, KeyError) as e:
373377
form = parsed_content.find("form")
374378
if form:
375379
data = parse_form_data(form)
@@ -456,7 +460,7 @@ def _parse_table_attributes(cls, table) -> Dict[str, str]:
456460
"""
457461
spell_rows = table.find_all("tr")
458462
attrs = {}
459-
for row in spell_rows[1:]:
463+
for row in spell_rows:
460464
cols = row.find_all("td")
461465
cols_text = [c.text for c in cols]
462466
clean_name = cols_text[0].replace(":", "").replace(" ", "_").lower().strip()

0 commit comments

Comments
 (0)