forked from mikeghen/python_api_samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_user_attribute_values.py
More file actions
35 lines (26 loc) · 966 Bytes
/
Copy pathget_user_attribute_values.py
File metadata and controls
35 lines (26 loc) · 966 Bytes
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
import yaml
from lookerapi import LookerApi
import csv
f = open('config.yml')
params = yaml.load(f)
f.close()
host = 'localhost'
my_host = params['hosts'][host]['host']
my_secret = params['hosts'][host]['secret']
my_token = params['hosts'][host]['token']
looker = LookerApi(host=my_host,
token=my_token,
secret = my_secret)
all_users = looker.get_user()
user_attributes = looker.get_user_attributes()
writer = csv.writer(open('user-attributes.csv', 'w'), delimiter=',',quotechar='"', quoting=csv.QUOTE_MINIMAL, lineterminator='\n')
headers = ['group_ids']
for attribute in user_attributes:
headers.append(attribute['name'])
writer.writerow(headers)
for u in all_users:
values = []
values.append(str(u['group_ids']).replace('[','').replace(']',''))
for attribute in user_attributes:
values.append(looker.get_user_attribute_values(u['id'],str(attribute['id']))[0]['value'])
writer.writerow(values)