async def fetch_news_archive(self, begin_date, end_date, categories=None, types=None): """Fetches news from the archive meeting the search criteria. Parameters ---------- begin_date: :class:`datetime.date` The beginning date to search dates in. end_date: :class:`datetime.date` The end date to search dates in. categories: `list` of :class:`NewsCategory` The allowed categories to show. If left blank, all categories will be searched. types : `list` of :class:`ListedNews` The allowed news types to show. if unused, all types will be searched. Returns ------- list of :class:`ListedNews` The news meeting the search criteria. Raises ------ ValueError: If ``begin_date`` is more recent than ``end_date``. Forbidden If a 403 Forbidden error was returned. This usually means that Tibia.com is rate-limiting the client because of too many requests. NetworkError If there's any connection errors during the request. """ if begin_date > end_date: raise ValueError("begin_date can't be more recent than end_date") if not categories: categories = list(NewsCategory) if not types: types = list(NewsType) data = { "filter_begin_day": begin_date.day, "filter_begin_month": begin_date.month, "filter_begin_year": begin_date.year, "filter_end_day": end_date.day, "filter_end_month": end_date.month, "filter_end_year": end_date.year, } for category in categories: key = "filter_%s" % category.value data[key] = category.value if NewsType.FEATURED_ARTICLE in types: data["filter_article"] = "article" if NewsType.NEWS in types: data["filter_news"] = "news" if NewsType.NEWS_TICKER in types: data["filter_ticker"] = "ticker" content = await self._post(News.get_list_url(), data) news = ListedNews.list_from_content(content) return news
async def test_client_fetch_boosted_creature(self, mock): """Testing fetching the boosted creature""" content = self.load_resource(self.FILE_UNRELATED_SECTION) mock.get(News.get_list_url(), status=200, body=content) creature = await self.client.fetch_boosted_creature() self.assertIsInstance(creature.data, BoostedCreature)
async def fetch_boosted_creature(self): """Fetches today's boosted creature. .. versionadded:: 2.1.0 Returns ------- :class:`BoostedCreature` The boosted creature of the day. Raises ------ Forbidden If a 403 Forbidden error was returned. This usually means that Tibia.com is rate-limiting the client because of too many requests. NetworkError If there's any connection errors during the request. """ content = await self._get(News.get_list_url()) boosted_creature = BoostedCreature.from_content(content) return boosted_creature