def _mal_fetch(session, kind, query, username, password):
"""Returns a bs4 tag or a string.
session is an aiohttp.ClientSession
kind should be either anime or manga
query is self-explanatory
username is self-explanatory
password is self-explanatory
"""
auth = aiohttp.BasicAuth(username, password)
query = urllib.parse.quote(query)
url = BASE_URL_MYANIMELIST_SEARCH.format(kind, query)
try: # This is gross, but MAL doesn't respond nicely.
async with session.request("GET", url, auth=auth) as response:
if response.status == 200:
xml = await response.text()
soup = BeautifulSoup(xml)
entry = soup.find("entry")
return entry
else:
message = "Could not reach MyAnimeList. x.x"
return message
except aiohttp.ClientResponseError:
message = ("No results found. Make sure you use spaces (e.g. "
"`one piece`, not `onepiece`). Also make sure to spell things right.")
return message
评论列表
文章目录