Created
February 25, 2017 23:14
-
-
Save gnilchee/8e60b85b8977713b8ef90acc7c9ac7a3 to your computer and use it in GitHub Desktop.
Track users status via slack api firehose (RTM)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from configparser import ConfigParser | |
from slackclient import SlackClient | |
config = ConfigParser() | |
config.read('slack.conf') | |
SLACK_TOKEN = config['slack']['SLACK_API_TOKEN'] | |
sc = SlackClient(SLACK_TOKEN) | |
if sc.rtm_connect(): | |
try: | |
while True: | |
for fh in sc.rtm_read(): | |
if fh['type'] == 'presence_change': | |
user_api_call = sc.api_call("users.list") | |
users = user_api_call.get('members') | |
for user in users: | |
if fh['user'] == user['id']: | |
who_are_they = user['real_name'] | |
res = "User: {}, Status: {}".format(who_are_they, fh['presence']) | |
print(res) | |
except KeyboardInterrupt: | |
print("Bye...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment