myanimelist.py 文件源码

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

项目:plumeria 作者: sk89q 项目源码 文件源码
def manga(message):
    """
    Gets information about an manga using myanimelist.net.

    Example::

        /manga naruto

    """
    query = message.content.strip()
    if not len(query):
        raise CommandError("Supply the name of a manga to search.")
    auth = aiohttp.BasicAuth(username(), password())
    try:
        r = await http.get("https://myanimelist.net/api/manga/search.xml", params=[
            ('q', query)
        ], auth=auth)
    except BadStatusCodeError as e:
        if e.http_code in (204, 404):
            raise CommandError("No manga results for '{query}'.".format(query=query))
        raise
    doc = BeautifulSoup(r.text(), features="lxml")
    entries = doc.manga.find_all("entry", recursive=False)
    if not len(entries):
        raise CommandError("No results found.")
    entry = entries[0]
    return "{image}\n\n" \
           "**{name}** ({type})\n\n" \
           "**Status:** {status}\n" \
           "**Score:** {score}\n" \
           "**Chapters:** {chapters}\n" \
           "**Run Dates:** {start}-{end}\n\n" \
           "{synopsis}\n".format(
        image=entry.image.text,
        type=entry.type.text,
        name=entry.title.text,
        status=entry.status.text,
        score=entry.score.text,
        chapters=entry.chapters.text,
        start=entry.start_date.text,
        end=entry.end_date.text,
        synopsis=strip_html(entry.synopsis.text),
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号