4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonからSlackに投稿

Last updated at Posted at 2016-02-29

PythonからSlackに投稿してみるテスト。投稿時は自分のSlack名+BOTとつくので場を読めない記述はBOTのせいにしてしまう作戦。

まずはSlackアプリから

スクリーンショット-2016-02-29-12.16.jpg

画像の箇所をクリックするとブラウザが立ちあがります。

t_スクリーンショット 2016-02-29 12.16.38.jpg

Build your ownをクリック。

t_スクリーンショット 2016-02-29 12.17.03.jpg

Make aうんたらをクリックします。

t_スクリーンショット 2016-02-29 12.17.15.jpg

次にIcoming WebHooksをクリックして投稿するURLを選択。
スクリプト内の保存したURLにペースト。

slackpost.py

# !/user/bin/env python
# -*- coding: utf-8 -*-
import requests
import json

while True:

	post_words = raw_input(u"words?: ")

	requests.post('保存したURL', data = json.dumps({
    	'text': post_words, # 投稿するテキスト
    	'username': u'投稿ユーザー名',
	}))


ターミナルから起動してひたすらWhileで周る奴の出来上がりです。色々Slack遊べるようなので、そろそろTwitter APIで遊ぶのを卒業(諦めて)し、Slackで遊んでみようと画策中。

4
6
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
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?