LoginSignup
1
3

More than 5 years have passed since last update.

Slackbotでwikipediaのランダムな記事を表示させる

Last updated at Posted at 2018-10-26

なんとなくネットを眺めていたらPythonのwikipediaモジュールなるものを発見しました。どうやらWikipediaのページを取得できるらしい…

ということでこちらで作ったBotに組み込んで使ってみました。

wikipedia.py
# coding: utf-8

from slackbot.bot import respond_to
import wikipedia

@respond_to('wikipedia')
def get_random_wikipedia_page(message):
    # set_langにjaを指定することで日本語の記事のみ取得します
    wikipedia.set_lang("ja")
    message.reply("https://ja.wikipedia.org/wiki/" + wikipedia.random())

以下、取得したページの一例。絶対自分では調べないようなページが出てきて、ちょっと楽しい。
スクリーンショット_2018-10-27_3_35_31.png
スクリーンショット_2018-10-27_3_35_47.png
スクリーンショット_2018-10-27_3_36_12.png
スクリーンショット_2018-10-27_3_36_22.png
スクリーンショット_2018-10-27_3_39_00.png

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3