コード例 #1
0
f = open('config.yml')
params = yaml.load(f)
f.close()

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)


### ------- GET ALL USERS -------

userlistarray = looker.get_all_users()
userlist = []

for user in userlistarray:
	userlist.append(user['id'])

### ------- GET ALL SCHEDULE ID/TITLES -----

scheduleattrlist = []

for user in userlist:
	data = looker.get_all_schedules(user)
	for schedule in data:
		scheduleattrlist.append({'id': schedule['id'],'title': schedule['title'] if schedule['title'] is not None else ""})

pprint(scheduleattrlist)
コード例 #2
0
new_look['query_id'] = content_usage_query['id']
new_look['title'] = "Unused Content"

look = looker.create_look(new_look)

print('Look Saved: ' + str(look['id']))

### ------- GET USER EMAILS FROM USER_IDs -------

data = looker.run_query(query_id=content_usage_query['id'])
user_ids = {row['user_id'] for row in data}

print('Users with unused content: ' + str(user_ids))

me = looker.get_current_user()
user_list = looker.get_all_users()
emails = {}
for u in user_list:
    if u['id'] in user_ids:
        emails[u['id']] = u['email']

print('Emails will be sent to: ' + str(emails))

### ------- CREATE SCHEDULE AND SEND NOTICE -------

schedule_body = {
    "name": "Unused Content",
    "title": "Unused Content",
    "user_id": me['id'],
    "run_once": "true"
}