diff options
| author | 2020-09-22 16:48:10 +0530 | |
|---|---|---|
| committer | 2020-09-22 16:48:10 +0530 | |
| commit | 34b86c4227f5f8ecd088d782c2e10195a2dc2c21 (patch) | |
| tree | b2cae03f2c5188a03951fbcc139be4e36395ea3d | |
| parent | corrected value error msg (diff) | |
handled exceptiom of ContentTypeError at search_wikipedia
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/evergreen/wikipedia.py | 21 | 
1 files changed, 12 insertions, 9 deletions
| diff --git a/bot/exts/evergreen/wikipedia.py b/bot/exts/evergreen/wikipedia.py index c1fff873..6cf8f592 100644 --- a/bot/exts/evergreen/wikipedia.py +++ b/bot/exts/evergreen/wikipedia.py @@ -3,6 +3,7 @@ import datetime  import logging  from typing import List +from aiohttp import client_exceptions  from discord import Color, Embed, Message  from discord.ext import commands @@ -28,18 +29,20 @@ class WikipediaCog(commands.Cog):      async def search_wikipedia(self, search_term: str) -> List[str]:          """Search wikipedia and return the first 10 pages found.""" -        async with self.http_session.get(SEARCH_API.format(search_term=search_term)) as response: -            data = await response.json() -          pages = [] +        async with self.http_session.get(SEARCH_API.format(search_term=search_term)) as response: +            try: +                data = await response.json() -        search_results = data["query"]["search"] +                search_results = data["query"]["search"] -        # Ignore pages with "may refer to" -        for search_result in search_results: -            log.info("trying to append titles") -            if "may refer to" not in search_result["snippet"]: -                pages.append(search_result["title"]) +                # Ignore pages with "may refer to" +                for search_result in search_results: +                    log.info("trying to append titles") +                    if "may refer to" not in search_result["snippet"]: +                        pages.append(search_result["title"]) +            except client_exceptions.ContentTypeError: +                pages = None          log.info("Finished appending titles")          return pages | 
