Slack にステータス機能が表示され絵文字と短いメッセージで自分の状態を表示できるようになりました
slackhq.com
API
APIでも変更できるみたいだったので触ってみました
users.profile.set method | Slack APIを使えば変更できます
テスターでWeb上でも試せます
トークンがない場合には以下のURLでとりあえず試せるトークンが取得できます
APIはtokenとuserとprofile({"status_text": "「新しくステータスに表示したいテキスト(長さは100まで)」", "status_emoji": "「新しくステータスに表示したい絵文字(例、:sushi:)」"}
)を指定すれば動きます(それぞれ空文字を指定すれば消せます)
ちなみにAPIを使うとなぜかステータスに改行が使えます
以下にPythonの擬似コードを書いておきます(requestsのライブラリを使っているので動かしたかったら入れてください)
import requests requests.post('https://slack.com/api/users.profile.set', params = { 'token': '「トークン」', 'user': '「ユーザーのID的なもの(APIのテスターで試せば簡単にわかる。OPTIONALらしいのでもしかしたら指定しなくても動くかも)」', 'profile': '{"status_text": "「新しくステータスに表示したいテキスト」", "status_emoji": "「新しくステータスに表示したい絵文字(例、:sushi:)」"}' })
天気予報を自動で取ってきて更新してみる
無料で使えるAPIがあまり見つからなかったです
以下のlivedoorが提供してくださっているJSON APIを使います
weather.livedoor.com
というわけでJSONをパースしてよしなにすると、毎日ステータスを使って天気予報を表示できるようになります
# coding: utf-8 import requests response = requests.get('http://weather.livedoor.com/forecast/webservice/json/v1?city=130010') data = response.json() text = '' for forecast in data['forecasts']: text += u'{} {}\n'.format(forecast['date'], forecast['telop']) emoji = u':sunny:' if len(data['forecasts']) >= 2: if u'雨' in data['forecasts'][1]['telop']: emoji = u':umbrella:' elif u'曇' in data['forecasts'][1]['telop']: emoji = u':cloud:' elif u'雪' in data['forecasts'][1]['telop']: emoji = u':snow_cloud:' text = text[:100] requests.post('https://slack.com/api/users.profile.set', params = { 'token': '「トークン」', 'user': '「ユーザーID」', 'profile': u'{{"status_text": "{}", "status_emoji": "{}"}}'.format(text, emoji) })