Skip to content

Commit 59fdef8

Browse files
committed
add client method for fansites and route to server
1 parent 60cd7cd commit 59fdef8

File tree

9 files changed

+168
-101
lines changed

9 files changed

+168
-101
lines changed

docs/api.rst

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

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/tests_fansites.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from tests.tests_tibiapy import TestCommons
2-
from tibiapy.models.fansites import FansitesSection
2+
from tibiapy.models.fansite import FansitesSection
33
from tibiapy.parsers.fansite import FansitesSectionParser
44

55
FILE_FANSITES_SECTION = "fansites/fansites.txt"

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/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 *

tibiapy/parsers/fansite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import bs4
44

55
from tibiapy import InvalidContentError
6-
from tibiapy.models.fansites import Fansite, FansiteContent, FansiteSocialMedia, FansitesSection
6+
from tibiapy.models.fansite import Fansite, FansiteContent, FansiteSocialMedia, FansitesSection
77
from tibiapy.utils import get_rows, parse_popup, parse_tibiacom_content
88

99

tibiapy/urls.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ def get_house_url(world: str, house_id: int) -> str:
176176
return get_tibia_url("community", "houses", page="view", houseid=house_id, world=world)
177177

178178

179+
def get_fansites_url() -> str:
180+
"""Get the Tibia.com URL for the fansites section.
181+
182+
Returns
183+
-------
184+
:class:`str`
185+
The URL to the fansites section.
186+
"""
187+
return get_tibia_url("community", "fansites")
188+
189+
179190
def get_world_overview_url() -> str:
180191
"""Get the URL to world overview section in Tibia.com.
181192

0 commit comments

Comments
 (0)