-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_slack.py
executable file
·40 lines (31 loc) · 1.02 KB
/
list_slack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
"""List items in slack."""
# https://github.com/os/slacker
# https://api.slack.com/methods
import os
import six
from slacker import Slacker
def list_slack():
"""List channels & users in slack."""
try:
token = os.environ["SLACK_TOKEN"]
slack = Slacker(token)
# Get channel list
response = slack.channels.list()
channels = response.body["channels"]
for channel in channels:
six.print_(channel["id"], channel["name"])
# if not channel['is_archived']:
# slack.channels.join(channel['name'])
six.print_()
# Get users list
response = slack.users.list()
users = response.body["members"]
for user in users:
if not user["deleted"]:
six.print_(user["id"], user["name"], user["is_admin"], user["is_owner"])
six.print_()
except KeyError as ex:
six.print_("Environment variable %s not set." % str(ex))
if __name__ == "__main__":
list_slack()