Skip to content

Commit 1aee357

Browse files
authored
Merge pull request #43 from Galarzaa90/feat-fansites
Add support for fansitese section
2 parents 8b164c7 + 0bf372e commit 1aee357

File tree

12 files changed

+1264
-99
lines changed

12 files changed

+1264
-99
lines changed

docs/api.rst

Lines changed: 110 additions & 93 deletions
Large diffs are not rendered by default.

docs/intro.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Supported Sections
107107
+----------------------------------+--------------------------------------------------------------+---------------------------------------------+
108108
| Guilds_ (Wars) | :meth:`tibiapy.parsers.GuildWarsParser.from_content` | :meth:`Client.fetch_guild_wars` |
109109
+----------------------------------+--------------------------------------------------------------+---------------------------------------------+
110+
| Fansites_ | :meth:`tibiapy.parsers.FansitesSectionParser.from_content` | :meth:`Client.fetch_fansites_section` |
111+
+----------------------------------+--------------------------------------------------------------+---------------------------------------------+
110112
| Forums_ (Section) | :meth:`tibiapy.parsers.ForumSectionParser.from_content` | :meth:`Client.fetch_forum_world_boards` |
111113
| | | :meth:`Client.fetch_forum_trade_boards` |
112114
| | | :meth:`Client.fetch_forum_community_boards` |
@@ -150,6 +152,7 @@ Supported Sections
150152
.. _Creature Library: https://www.tibia.com/library/?subtopic=creatures
151153
.. _Event Schedule: https://www.tibia.com/news/?subtopic=eventcalendar
152154
.. _Guilds: https://www.tibia.com/community/?subtopic=guilds
155+
.. _Fansites: https://www.tibia.com/community/?subtopic=fansites
153156
.. _Forums: https://www.tibia.com/community/?subtopic=forum
154157
.. _Highscores: https://www.tibia.com/community/?subtopic=highscores
155158
.. _Houses: https://www.tibia.com/community/?subtopic=houses

server.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
PvpTypeFilter,
1818
SpellGroup, SpellSorting, SpellType, SpellVocationFilter)
1919
from tibiapy.models import (Auction, AuctionFilters, BoostableBosses, BossEntry, Character, CharacterBazaar, Creature,
20-
CreatureEntry, CreaturesSection, EventSchedule, ForumBoard, ForumSection, ForumThread,
20+
CreatureEntry, CreaturesSection, EventSchedule, FansitesSection, ForumBoard, ForumSection,
21+
ForumThread,
2122
Guild, GuildWars,
2223
GuildsSection, Highscores, House, HousesSection, KillStatistics, Leaderboard, News,
2324
NewsArchive, Spell,
@@ -297,6 +298,17 @@ async def get_leaderboard(
297298
)
298299

299300

301+
@app.get("/fansites", tags=["Community"])
302+
async def get_fansites(
303+
response: Response,
304+
) -> TibiaResponse[FansitesSection]:
305+
"""Show the fansites section."""
306+
return handle_response(
307+
response,
308+
await app.state.client.fetch_fansites_section(),
309+
)
310+
311+
300312
# endregion
301313

302314
# region Forums

tests/resources/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ trying to cover as many scenarios possible, to be used in unit tests.
193193
- [worldOverviewOnline.txt](worldOverview/worldOverviewOnline.txt) - The world list with all worlds online.
194194
- [worldOverviewOffline.txt](worldOverview/worldOverviewOffline.txt) - The world list with all worlds offline.
195195

196+
## Fansites
197+
198+
- [fansites.txt](fansites/fansites.txt) - The fansites section.
199+
196200
## Other
197201

198202
- [tibiacom_about.txt](aboutSection.txt) - The 'About Tibia' section on Tibia.com, used to provide invalid content for tests.
203+

tests/resources/fansites/fansites.txt

Lines changed: 921 additions & 0 deletions
Large diffs are not rendered by default.

tests/tests_fansites.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from tests.tests_tibiapy import TestCommons
2+
from tibiapy.models.fansite import FansitesSection
3+
from tibiapy.parsers.fansite import FansitesSectionParser
4+
5+
FILE_FANSITES_SECTION = "fansites/fansites.txt"
6+
7+
8+
class TestFansitesSection(TestCommons):
9+
def test_fansites_parser_from_content(self):
10+
"""Testing parsing the fansites section."""
11+
content = self.load_resource(FILE_FANSITES_SECTION)
12+
fansites_section = FansitesSectionParser.from_content(content)
13+
14+
self.assertIsInstance(fansites_section, FansitesSection)
15+
self.assertIsNotEmpty(fansites_section.promoted_fansites)
16+
self.assertIsNotEmpty(fansites_section.supported_fansites)

tibiapy/client.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@
1919
from tibiapy.models import TibiaResponse
2020
from tibiapy.parsers import (
2121
AuctionParser, BoostableBossesParser, BoostedCreaturesParser, CMPostArchiveParser, CharacterBazaarParser,
22-
CharacterParser, CreatureParser, CreaturesSectionParser, EventScheduleParser, ForumAnnouncementParser,
22+
CharacterParser, CreatureParser, CreaturesSectionParser, EventScheduleParser, FansitesSectionParser,
23+
ForumAnnouncementParser,
2324
ForumBoardParser, ForumSectionParser, ForumThreadParser, GuildParser, GuildWarsParser, GuildsSectionParser,
2425
HighscoresParser, HouseParser, HousesSectionParser, KillStatisticsParser, LeaderboardParser, NewsArchiveParser,
2526
NewsParser, SpellParser, SpellsSectionParser, WorldOverviewParser, WorldParser,
2627
)
2728
from tibiapy.urls import (
2829
get_auction_url, get_bazaar_url, get_boostable_bosses_url, get_character_url, get_cm_post_archive_url,
2930
get_community_boards_url, get_creature_url, get_creatures_section_url, get_event_schedule_url,
30-
get_forum_announcement_url, get_forum_board_url, get_forum_post_url, get_forum_section_url, get_forum_thread_url,
31+
get_fansites_url, get_forum_announcement_url, get_forum_board_url, get_forum_post_url, get_forum_section_url,
32+
get_forum_thread_url,
3133
get_guild_url, get_guild_wars_url, get_highscores_url, get_house_url, get_houses_section_url,
3234
get_kill_statistics_url, get_leaderboards_url, get_news_archive_url, get_news_url, get_spell_url,
3335
get_spells_section_url, get_support_boards_url, get_trade_boards_url, get_world_boards_url, get_world_guilds_url,
@@ -37,9 +39,9 @@
3739
if TYPE_CHECKING:
3840
from tibiapy.models import (
3941
AjaxPaginator, Auction, AuctionFilters, BoostableBosses, BoostedCreatures, BossEntry, CMPostArchive, Character,
40-
CharacterBazaar, Creature, CreatureEntry, CreaturesSection, EventSchedule, ForumAnnouncement, ForumBoard,
41-
ForumSection, ForumThread, Guild, GuildWars, GuildsSection, Highscores, House, HousesSection, KillStatistics,
42-
Leaderboard, News, NewsArchive, Spell, SpellsSection, World, WorldOverview,
42+
CharacterBazaar, Creature, CreatureEntry, CreaturesSection, EventSchedule, FansitesSection, ForumAnnouncement,
43+
ForumBoard, ForumSection, ForumThread, Guild, GuildWars, GuildsSection, Highscores, House, HousesSection,
44+
KillStatistics, Leaderboard, News, NewsArchive, Spell, SpellsSection, World, WorldOverview,
4345
)
4446

4547
__all__ = (
@@ -1035,6 +1037,32 @@ async def fetch_guild_wars(self, name: str, *, test: bool = False) -> TibiaRespo
10351037
response = await self._request("GET", get_guild_wars_url(name), test=test)
10361038
return response.parse(GuildWarsParser.from_content)
10371039

1040+
async def fetch_fansites_section(self, *, test: bool = False) -> TibiaResponse[FansitesSection]:
1041+
"""Fetch the fansites section from Tibia.com.
1042+
1043+
.. versionadded:: 6.2.0
1044+
1045+
Parameters
1046+
----------
1047+
test:
1048+
Whether to request the test website instead.
1049+
1050+
Returns
1051+
-------
1052+
TibiaResponse[FansitesSection]
1053+
A response containing the fansites section.
1054+
1055+
Raises
1056+
------
1057+
Forbidden
1058+
If a 403 Forbidden error was returned.
1059+
This usually means that Tibia.com is rate-limiting the client because of too many requests.
1060+
NetworkError
1061+
If there's any connection errors during the request.
1062+
"""
1063+
response = await self._request("GET", get_fansites_url(), test=test)
1064+
return response.parse(FansitesSectionParser.from_content)
1065+
10381066
# endregion
10391067

10401068
# region Forums

tibiapy/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from tibiapy.models.character import *
55
from tibiapy.models.creature import *
66
from tibiapy.models.event import *
7+
from tibiapy.models.fansite import *
78
from tibiapy.models.forum import *
89
from tibiapy.models.guild import *
910
from tibiapy.models.highscores import *

tibiapy/models/fansite.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from typing import List, Optional
2+
3+
from tibiapy.models import BaseModel
4+
5+
__all__ = (
6+
"FansiteContent",
7+
"FansiteSocialMedia",
8+
"Fansite",
9+
"FansitesSection",
10+
)
11+
12+
13+
class FansiteContent(BaseModel):
14+
"""An icon to represent a category of content."""
15+
16+
name: str
17+
"""The name of the content category."""
18+
icon_url: str
19+
"""URL to the icon."""
20+
21+
22+
class FansiteSocialMedia(BaseModel):
23+
"""An icon to represent available social media for the fansite."""
24+
25+
name: str
26+
"""The name of the social media site."""
27+
icon_url: str
28+
"""The URL to the icon."""
29+
30+
31+
class Fansite(BaseModel):
32+
"""Represents a fansite in the fansite programme."""
33+
34+
name: str
35+
"""The name of the fansite."""
36+
url: str
37+
"""The URL to the fansite."""
38+
logo_url: str
39+
"""URL to the fansite's logo."""
40+
contact: str
41+
"""The name of the contact person."""
42+
content: List[FansiteContent]
43+
"""A list of content categories for the site."""
44+
social_media: List[FansiteSocialMedia]
45+
"""A list of the social media sites the fansite has."""
46+
languages: List[str]
47+
"""A list of the languages the site is available in."""
48+
specials: List[str]
49+
"""A description of features or highligts."""
50+
fansite_item_image_url: Optional[str]
51+
"""The URL to the fansite item's icon, if available."""
52+
53+
54+
class FansitesSection(BaseModel):
55+
"""The fansites section of Tibia.com."""
56+
57+
promoted_fansites: List[Fansite]
58+
"""Promoted fansites."""
59+
supported_fansites: List[Fansite]
60+
"""Supported fansites."""

tibiapy/parsers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from tibiapy.parsers.character import *
33
from tibiapy.parsers.creature import *
44
from tibiapy.parsers.event import *
5+
from tibiapy.parsers.fansite import *
56
from tibiapy.parsers.forum import *
67
from tibiapy.parsers.guild import *
78
from tibiapy.parsers.highscores import *

0 commit comments

Comments
 (0)