forked from mikeghen/python_api_samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_cleanup_part2.py
More file actions
44 lines (31 loc) · 1.69 KB
/
content_cleanup_part2.py
File metadata and controls
44 lines (31 loc) · 1.69 KB
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
import yaml
from lookerapi import LookerApi
### ------- HERE ARE PARAMETERS TO CONFIGURE -------
look_id = 123 # Look created in part1
host = 'localhost'
### ------- OPEN THE CONFIG FILE and INSTANTIATE API -------
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)
data = looker.get_look(look_id=look_id, format='json')
soft_delete = {"deleted": True} #applies to both look and dashboard patchs
for d in data:
print('Soft deleting ' + d['content_usage.content_type'] + ': ' + d['content_usage.content_id'])
if d['content_usage.content_type'] == 'look':
# looker.update_look(d['content_usage.content_id'],body=soft_delete) # uncomment this line to soft delete
elif d['content_usage.content_type'] == 'dashboard':
looks_to_delete = []
dashboard_looks = looker.get_dashboard(d['content_usage.content_id'],fields="dashboard_elements(look_id)")
if dashboard_looks:
looks_to_delete = looks_to_delete + [look['look_id'] for look in dashboard_looks['dashboard_elements']]
# dashboard_updated = looker.update_dashboard(d['content_usage.content_id'],body=soft_delete) # uncomment this line to soft delete
for look_id in looks_to_delete:
# look_updated = looker.update_look(look_id,body=soft_delete,fields='id') # uncomment this line to soft delete
if look_updated:
print("Soft deleting look: " + str(look_updated['id']) + ' on dashboard: ' + str(d['content_usage.content_id']))