forked from os/slacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.py
executable file
·39 lines (31 loc) · 1 KB
/
list.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
#!/usr/bin/env python
"""List items in slack."""
# https://github.com/os/slacker
# https://api.slack.com/methods
import os
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:
print(channel['id'], channel['name'])
# if not channel['is_archived']:
# slack.channels.join(channel['name'])
print()
# Get users list
response = slack.users.list()
users = response.body['members']
for user in users:
if not user['deleted']:
print(user['id'], user['name'], user['is_admin'], user[
'is_owner'])
print()
except KeyError as ex:
print('Environment variable %s not set.' % str(ex))
if __name__ == '__main__':
list_slack()