wikipedia.py 文件源码

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

项目:pyconjpbot 作者: pyconjp 项目源码 文件源码
def wikipedia_page(message, option, query):
    """
    Wikipedia??????????
    """
    if query == 'help':
        return

    # set language
    lang = 'ja'
    if option:
        _, lang = option.split('-')
    wikipedia.set_lang(lang)

    try:
        # search with query
        results = wikipedia.search(query)
    except:
        botsend(message, '??????? `{}` ???????'.format(lang))
        return

    # get first result
    if results:
        page = wikipedia.page(results[0])

        attachments = [{
            'fallback': 'Wikipedia: {}'.format(page.title),
            'pretext': 'Wikipedia: <{}|{}>'.format(page.url, page.title),
            'text': page.summary,
        }]
        botwebapi(message, attachments)
    else:
        botsend(message, '`{}` ??????????????'.format(query))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号