-
Notifications
You must be signed in to change notification settings - Fork 0
/
getuserlist.py
36 lines (31 loc) · 1.49 KB
/
getuserlist.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
import slackclient
import os
import json
# You must create an environment variable with your slack api key, and then pull it into python here.
key = os.getenv('SLACK_KEY')
sc = slackclient.SlackClient(key)
userlist = {} # ul is just a name for userlist
# Use the user.list api call to pull the users and add them to our userlist dictionary.
def GetUserList(ul=userlist):
returned = sc.api_call('users.list')
if returned['ok'] == True:
for member in returned['members']:
ul[member['name']] = member
return ul
# For each entry in the ul dictionary, print the values in a foratted way.
# Has option to hide image urls. In the "Profile" section there's a bunch of long image urls.
def PrintUserList(ul=userlist,hide_images=1):
for user in ul:
print('\nUser: ' + str(user))
for user_attribute in sorted(ul[user]):
if user_attribute == 'profile': # the profile attribute has sub-items
print(str(user_attribute) + ':')
for profile_item in sorted(ul[user][user_attribute]):
if profile_item[0:5] == 'image' and hide_images == 1:
pass
else:
print('\t' + str(profile_item) + ': ' + str(ul[user][user_attribute][profile_item]))
else:
print(str(user_attribute) + ': ' + str(ul[user][user_attribute]))
print(GetUserList()) # Prints the user list dictionary
print(PrintUserList()) # Prints our foratted version.