myanimelist.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:kitsuchan-2 作者: n303p4 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号