Help us understand the problem. What is going on with this article?

PythonでSlackのステータスを変える

More than 1 year has passed since last update.

最近Slackにステータスの機能が実装されました。ミーティング中や帰宅済みなど名前の横を見ればステータスがわかるようになって非常に便利です。
https://get.slack.help/hc/ja/articles/201864558-Slack-%E3%81%AE%E3%82%B9%E3%83%86%E3%83%BC%E3%82%BF%E3%82%B9%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B

APIが公開されていてトークンがあればSlackの外から変更できます。
https://api.slack.com/methods/users.profile.set

トークンの取得はこちらから
https://api.slack.com/custom-integrations/legacy-tokens

以下はPython3でのコードになります。

環境

  • python 3.6.0
  • requests 2.13.0

コード

import requests
import json
import sys

arguments = sys.argv
text = arguments[1]
emoji = arguments[2]
url = "https://slack.com/api/users.profile.set"
params = {
        'token': 'your_token',
        'profile': json.dumps(
            {
                "status_text": text,
                "status_emoji": emoji
            }
        )
}
headers = {'Content-Type': 'application/json'}
r = requests.get(url, params=params, headers=headers)
print(r.url)
print(r.text)

実行

python3 change_slack_status.py "In meeting" ":spiral_calendar_pad:"
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away