diff options
author | 2021-08-07 20:54:48 +0200 | |
---|---|---|
committer | 2021-08-07 22:22:12 +0200 | |
commit | 8532b4099baefb7000cb467fafc94688c1c04db9 (patch) | |
tree | df506aacdb6d5f552818e737b9e8502d7ddd2f2f | |
parent | Update the movie cog to use aiohttp get params (diff) |
Update the Wikipedia Cog to use aiohttp get params
-rw-r--r-- | bot/exts/evergreen/wikipedia.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/bot/exts/evergreen/wikipedia.py b/bot/exts/evergreen/wikipedia.py index 83937438..28bbf0de 100644 --- a/bot/exts/evergreen/wikipedia.py +++ b/bot/exts/evergreen/wikipedia.py @@ -13,9 +13,18 @@ from bot.utils import LinePaginator log = logging.getLogger(__name__) SEARCH_API = ( - "https://en.wikipedia.org/w/api.php?action=query&list=search&prop=info&inprop=url&utf8=&" - "format=json&origin=*&srlimit={number_of_results}&srsearch={string}" + "https://en.wikipedia.org/w/api.php" ) +WIKI_PARAMS = { + "action": "query", + "list": "search", + "prop": "info", + "inprop": "url", + "utf8": "", + "format": "json", + "origin": "*", + +} WIKI_THUMBNAIL = ( "https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg" "/330px-Wikipedia-logo-v2.svg.png" @@ -35,8 +44,8 @@ class WikipediaSearch(commands.Cog): async def wiki_request(self, channel: TextChannel, search: str) -> Optional[List[str]]: """Search wikipedia search string and return formatted first 10 pages found.""" - url = SEARCH_API.format(number_of_results=10, string=search) - async with self.bot.http_session.get(url=url) as resp: + params = dict(WIKI_PARAMS, srlimit=10, srsearch=search) + async with self.bot.http_session.get(url=SEARCH_API, params=params) as resp: if resp.status == 200: raw_data = await resp.json() number_of_results = raw_data["query"]["searchinfo"]["totalhits"] |