bible.py 文件源码

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

项目:plumeria 作者: sk89q 项目源码 文件源码
def search_esv(message, verse):
    """
    Search for a bible passage from the English Standard Version.

    Example::

        bible Romans 12:16

    """
    r = await http.get("http://www.esvapi.org/v2/rest/passageQuery", params={
        "key": "IP",
        "passage": verse,
        "output-format": "crossway-xml-1.0",
        "include-simple-entities": "true",
    })

    doc = BeautifulSoup(r.text(), features="lxml")
    if not doc.passage:
        raise CommandError("Verse not found.")
    lines = []
    for verse_unit in doc.passage.content.find_all('verse-unit'):
        num = int(verse_unit.find('verse-num').text)
        woc = verse_unit.find('woc')
        if woc:
            text = woc.text
        else:
            text = "".join([str(node) for node in verse_unit.children
                            if isinstance(node, NavigableString) and not isinstance(node, Comment)])
        lines.append("**{}** {}".format(num, text.strip()))
    return "\n".join(lines)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号