-
Notifications
You must be signed in to change notification settings - Fork 0
/
people.py
25 lines (21 loc) · 879 Bytes
/
people.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
import csv
import data
def _read_reference_users():
with open('users.csv', 'r') as f:
return dict([(user['id'], user) for user in csv.DictReader(f)])
reference_users = _read_reference_users()
def get_user_channels(workspace, user):
""" Find channels in `workspace` where the `user` is a member """
channels = data.channels(workspace)
return [channel for channel in channels if user in data.channel_info(workspace, channel)['members']]
def workspace_users(workspace):
""" All users in `workspace` and channels where they are member """
channels = data.channels(workspace)
users = {}
for channel in channels:
members = data.channel_info(workspace, channel)['members']
for member in members:
if member not in users:
users[member] = []
users[member].append(channel)
return users