From e78b55a22e6b4ec2ff66ef99aa0ab34c51ec5ede Mon Sep 17 00:00:00 2001 From: Allan Galarza Date: Thu, 22 Aug 2019 21:45:54 -0700 Subject: [PATCH] Fixed account badges not being parsed --- CHANGELOG.rst | 7 ++ .../character/tibiacom_title_badges.txt | 79 +++++++++++++++---- tests/tests_character.py | 11 ++- tibiapy/__init__.py | 2 +- tibiapy/character.py | 21 +++-- 5 files changed, 88 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e884c1b9..40ed4416 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,13 @@ Changelog Due to this library relying on external content, older versions are not guaranteed to work. Try to always use the latest version. +.. _v2.2.5: + +2.2.5 (2019-08-22) +================== + +- Fixed account badges parsing due to changes on the layout by CipSoft. + .. _v2.2.4: 2.2.4 (2019-08-20) diff --git a/tests/resources/character/tibiacom_title_badges.txt b/tests/resources/character/tibiacom_title_badges.txt index 0aeb4c15..155f5f37 100644 --- a/tests/resources/character/tibiacom_title_badges.txt +++ b/tests/resources/character/tibiacom_title_badges.txt @@ -1,31 +1,72 @@
-
Character Information
Name:Lord Feremis
Former Names:Lady Yanine
Title:None (6 titles unlocked)
Sex:male
Vocation:Elder Druid
Level:212
Achievement Points:140
World:Gladera
Residence:Roshamuul
House: Unklath I b (Ankrahmun) is paid until Aug 15 2019
Guild Membership:Amigo Mexicano of the Club de amigos
Last Login:Aug 06 2019, 01:34:07 CEST
Account Status:Premium Account
-

Account Badges
Ancient HeroAncient Hero
Senior HeroSenior Hero
Veteran HeroVeteran Hero
Fledgeling HeroFledgeling Hero
Tibia Loyalist (Grade 1)Tibia Loyalist (Grade 1)


Account Achievements
Tibia AchievementNumber of the Beast
Tibia AchievementRockstarTibia Secret Achievement
Tibia AchievementSafely Stored AwayTibia Secret Achievement
Tibia AchievementTibia AchievementTurncoatTibia Secret Achievement
Tibia AchievementVanityTibia Secret Achievement


Character Deaths
Jul 31 2019, 21:55:40 CESTDied at Level 206 by a grim reaper.
Jul 27 2019, 01:30:26 CESTDied at Level 203 by a gazer spectre.
Jul 21 2019, 02:12:12 CESTDied at Level 190 by a skeleton elite warrior.
Jul 16 2019, 06:48:23 CESTDied at Level 183 by a frazzlemaw.


Account Information
Loyalty Title:Warden of Tibia
Created:Jun 19 2003, 05:26:35 CEST


Characters
NameWorldStatus #160;
1. Chicharron De CacheteGladera
- - +
Character Information
Name:Galarzaa Fidera
Title:Gold Hoarder (8 titles unlocked)
Sex:male
Vocation:Paladin
Level:285
Achievement Points:406
World:Gladera
Residence:Thais
Married To:Auron Freezecaster
Guild Membership:Keeper of the Redd Alliance
Last Login:Aug 20 2019, 05:41:26 CEST
Comment:03/11/15 - Character created
+09/01/16 - Level 100
+07/02/16 - Mortal Combat (Level 122)
+29/02/16 - Cave Explorer Outfit (Level 135)
+04/04/16 - Annihilator Quest (Level 152) with Nezune, Miraxe and Ir Yut
+01/04/19 - Nezune deleted by almighty and completely accurate CipSoft detection tool.
+
+† RIP Nezune - Don't get hunted by Pablinn in Deletera †
+
+NabBot's support discord server:
+https://support.nabbot.xyz/
+
+/NB-23FC13AC7400000/
+
Account Status:Free Account
+

Account Badges
Ancient Hero
Senior Hero
Veteran Hero
Fledgeling Hero
Tibia Loyalist (Grade 1)
Global Player (Grade 1)


Account Achievements
Tibia AchievementCave Completionist
Tibia AchievementDream's Over
Tibia AchievementTibia AchievementFriend of the Apes
Tibia AchievementTibia AchievementTrue LightbearerTibia Secret Achievement
Tibia AchievementTibia AchievementWarlord of Svargrond


Account Information
Loyalty Title:Warden of Tibia
Created:May 22 2004, 06:35:43 CEST


Characters
NameWorldStatus 
1. Don HeronAntica
+ +
-
2. IztliGladera
- - +
2. Eggplant GalarzaaSecura
+ +
-
3. Lord Feremis (Main Character)Gladeraonline
- - +
3. GalarzaaCalmera
+ +
-
4. Oxy DadoKenora
- - +
4. Galarzaa DeathbringerGladera
+ +
-
5. Tamnpic HugoLobera
- - +
5. Galarzaa Fidera (Main Character)Gladera
+ + +
+
6. Galarzaa ReddGladera
+ + +
+
7. Galarzaa The DruidGladera
+ + +
+
8. Gallan DoenteBelobra
+ + +
+
9. Lord de los DruidasCalmera
+ + +
+
10. Porfirio Diaz MoriTournament - restricted Store
+ + +
+
11. Sir GalarzaaCalmera
+ + +
+
12. Sir HeronZunera
+ +


Search Character
- +
Name:Name:
@@ -33,3 +74,7 @@ +
+
+
+ \ No newline at end of file diff --git a/tests/tests_character.py b/tests/tests_character.py index 3f84798f..7763dd0c 100644 --- a/tests/tests_character.py +++ b/tests/tests_character.py @@ -105,12 +105,11 @@ def test_character_from_content_badges_and_title(self): """Testing parsing a character with account badges and a title""" content = self._load_resource(FILE_CHARACTER_TITLE_BADGES) char = Character.from_content(content) - self.assertEqual("Lord Feremis", char.name) - self.assertEqual(140, char.achievement_points) - self.assertIsNone(char.title) - self.assertEqual(6, char.unlocked_titles) - self.assertEqual(5, len(char.account_badges)) - self.assertEqual(1, len(char.former_names)) + self.assertEqual("Galarzaa Fidera", char.name) + self.assertEqual(406, char.achievement_points) + self.assertEqual("Gold Hoarder", char.title) + self.assertEqual(8, char.unlocked_titles) + self.assertEqual(6, len(char.account_badges)) for badge in char.account_badges: self.assertIsInstance(badge, AccountBadge) self.assertIsInstance(badge.name, str) diff --git a/tibiapy/__init__.py b/tibiapy/__init__.py index 7a6748ca..1f0396fd 100644 --- a/tibiapy/__init__.py +++ b/tibiapy/__init__.py @@ -13,7 +13,7 @@ from tibiapy.creature import * from tibiapy.client import * -__version__ = '2.2.4' +__version__ = '2.2.5' from logging import NullHandler diff --git a/tibiapy/character.py b/tibiapy/character.py index aed67590..6333bb4a 100644 --- a/tibiapy/character.py +++ b/tibiapy/character.py @@ -31,6 +31,7 @@ guild_regexp = re.compile(r'([\s\w()]+)\sof the\s(.+)') title_regexp = re.compile(r'(.*)\((\d+) titles unlocked\)') +badge_popup_regexp = re.compile(r"\$\(this\),\s+'([^']+)',\s+'([^']+)',") __all__ = ( "AccountBadge", @@ -295,7 +296,8 @@ def from_content(cls, content): else: raise InvalidContent("content does not contain a tibia.com character information page.") char._parse_achievements(tables.get("Account Achievements", [])) - char._parse_badges(tables.get("Account Badges", [])) + if "Account Badges" in tables: + char._parse_badges(tables["Account Badges"]) char._parse_deaths(tables.get("Character Deaths", [])) char._parse_account_information(tables.get("Account Information", [])) char._parse_other_characters(tables.get("Characters", [])) @@ -429,14 +431,17 @@ def _parse_badges(self, rows): rows: :class:`list` of :class:`bs4.Tag` A list of all rows contained in the table. """ - for row in rows: - cols = row.find_all('td') - if len(cols) != 2: + row = rows[0] + columns = row.find_all('td') + for column in columns: + popup = column.find("span", attrs={"class": "HelperDivIndicator"}) + m = badge_popup_regexp.search(popup['onmouseover']) + if m: + name = m.group(1) + description = m.group(2) + else: continue - icon, text = cols - name = text.text.strip() - icon_image = icon.find("img") - description = icon_image['title'] + icon_image = column.find("img") icon_url = icon_image['src'] self.account_badges.append(AccountBadge(name, icon_url, description))