-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathget_users.py
executable file
·45 lines (35 loc) · 1.19 KB
/
get_users.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
41
42
43
44
45
#!/usr/bin/env python
from json_utils import load_json, dump_json
from slackclient import SlackClient
import operator
import os
import argparse
def ensure_dir(directory):
if not os.path.exists(directory):
os.makedirs(directory)
return directory
config = load_json('./env.json')
if __name__ == '__main__':
ap = argparse.ArgumentParser()
ap.add_argument('-u', '--update', help = 'update channels', action="store_true")
args = vars(ap.parse_args())
slack_args = {
'presence': 1
}
sc = SlackClient(config['token'])
response = sc.api_call('users.list', **slack_args)
users = response['members']
for user in users:
user_name = user['name']
memb_path = ensure_dir('./output/users/members')
user_path = '{}/{}.json'.format(memb_path, user_name)
try:
old_json = load_json(user_path)
if not args['update']:
print('Aready have user {}, skipping...'.format(user_name))
continue
except Exception as e:
old_json = {}
print('No existing messages, starting from scratch...')
print('ADDING ', user_name)
dump_json(user_path, user)