|
13 | 13 | from tibiapy.enums import Category, HouseOrder, HouseStatus, HouseType, NewsCategory, NewsType, VocationFilter
|
14 | 14 | from tibiapy.errors import Forbidden, NetworkError
|
15 | 15 | from tibiapy.event import EventSchedule
|
16 |
| -from tibiapy.forum import CMPostArchive, ForumAnnouncement, ForumBoard, ForumThread, ListedBoard |
| 16 | +from tibiapy.forum import CMPostArchive, ForumAnnouncement, ForumBoard, ForumPost, ForumThread, ListedBoard |
17 | 17 | from tibiapy.guild import Guild, GuildWars, ListedGuild
|
18 | 18 | from tibiapy.highscores import Highscores
|
19 | 19 | from tibiapy.house import House, ListedHouse
|
@@ -419,6 +419,41 @@ async def fetch_forum_thread(self, thread_id, page=1):
|
419 | 419 | parsing_time = time.perf_counter() - start_time
|
420 | 420 | return TibiaResponse(response, thread, parsing_time)
|
421 | 421 |
|
| 422 | + async def fetch_forum_post(self, post_id): |
| 423 | + """Fetches a forum post with a given id. |
| 424 | +
|
| 425 | + The thread that contains the post will be returned, containing the desired post in |
| 426 | + :py:attr:`ForumThread.anchored_post`. |
| 427 | +
|
| 428 | + The displayed page will be the page where the post is located. |
| 429 | +
|
| 430 | + .. versionadded:: 3.1.0 |
| 431 | +
|
| 432 | + Parameters |
| 433 | + ---------- |
| 434 | + post_id : :class:`int` |
| 435 | + The id of the post. |
| 436 | +
|
| 437 | + Returns |
| 438 | + ------- |
| 439 | + :class:`TibiaResponse` of :class:`ForumThread` |
| 440 | + A response containing the forum, if found. |
| 441 | +
|
| 442 | + Raises |
| 443 | + ------ |
| 444 | + Forbidden |
| 445 | + If a 403 Forbidden error was returned. |
| 446 | + This usually means that Tibia.com is rate-limiting the client because of too many requests. |
| 447 | + NetworkError |
| 448 | + If there's any connection errors during the request.""" |
| 449 | + response = await self._request("get", ForumPost.get_url(post_id)) |
| 450 | + start_time = time.perf_counter() |
| 451 | + thread = ForumThread.from_content(response.content) |
| 452 | + if thread: |
| 453 | + thread.anchored_post = next((p for p in thread.posts if p.post_id == post_id), None) |
| 454 | + parsing_time = time.perf_counter() - start_time |
| 455 | + return TibiaResponse(response, thread, parsing_time) |
| 456 | + |
422 | 457 | async def fetch_forum_announcement(self, announcement_id):
|
423 | 458 | """Fetches a forum announcement.
|
424 | 459 |
|
|
0 commit comments