-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Galarzaa90/dev
v2.1.0
- Loading branch information
Showing
18 changed files
with
254 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tests/resources/tournaments/tournament_information_running.txt
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
tests/resources/tournaments/tournament_leaderboards_running.txt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import unittest | ||
|
||
from tests.tests_tibiapy import TestCommons | ||
from tibiapy import BoostedCreature, InvalidContent | ||
|
||
|
||
class TestCreature(TestCommons, unittest.TestCase): | ||
# region Tibia.com Tests | ||
def testBoostedCreature(self): | ||
content = self._load_resource(self.FILE_UNRELATED_SECTION) | ||
creature = BoostedCreature.from_content(content) | ||
|
||
self.assertIsInstance(creature, BoostedCreature) | ||
self.assertEqual("Skeleton Warrior", creature.name) | ||
|
||
def testBoostedCreatureNotTibiaCom(self): | ||
with self.assertRaises(InvalidContent): | ||
BoostedCreature.from_content("<html><div><p>Nothing</p></div></html>") | ||
|
||
# endregion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import bs4 | ||
|
||
from tibiapy import abc, InvalidContent | ||
|
||
__all__ = ( | ||
"BoostedCreature", | ||
) | ||
|
||
BOOSTED_ALT = "Today's boosted creature: " | ||
|
||
|
||
class BoostedCreature(abc.Serializable): | ||
"""Represents a boosted creature entry. | ||
This creature changes every server save and applies to all Game Worlds. | ||
Boosted creatures yield twice the amount of experience points, carry more loot and respawn at a faster rate. | ||
Attributes | ||
---------- | ||
name: :class:`str` | ||
The name of the boosted creature. | ||
image_url: :class:`str` | ||
An URL containing the boosted creature's image. | ||
""" | ||
__slots__ = ( | ||
"name", | ||
"image_url", | ||
) | ||
|
||
def __init__(self, name, image_url): | ||
self.name = name | ||
self.image_url = image_url | ||
|
||
def __repr__(self): | ||
return "<{0.__class__.__name__} name={0.name!r} image_url={0.image_url!r}>".format(self) | ||
|
||
@classmethod | ||
def from_content(cls, content): | ||
""" | ||
Gets the boosted creature from any Tibia.com page. | ||
Parameters | ||
---------- | ||
content: :class:`str` | ||
The HTML content of a Tibia.com page. | ||
Returns | ||
------- | ||
:class:`News` | ||
The boosted article shown. | ||
Raises | ||
------ | ||
InvalidContent | ||
If content is not the HTML of a Tibia.com's page. | ||
""" | ||
try: | ||
parsed_content = bs4.BeautifulSoup(content.replace('ISO-8859-1', 'utf-8'), "lxml", | ||
parse_only=bs4.SoupStrainer("div", attrs={"id": "RightArtwork"})) | ||
img = parsed_content.find("img", attrs={"id": "Monster"}) | ||
name = img["title"].replace(BOOSTED_ALT, "").strip() | ||
image_url = img["src"] | ||
return cls(name, image_url) | ||
except TypeError: | ||
raise InvalidContent("content is not from Tibia.com") | ||
|
Oops, something went wrong.