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) looks_to_delete = [] soft_delete = {"deleted": True} #applies to both look and dashboard patchs for dashboard_id in args.dashboards.split(','): dashboard_looks = looker.get_dashboard( dashboard_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(dashboard_id, body=soft_delete, fields='id') pprint("Soft deleted dashboard id " + str(dashboard_updated['id'])) for look_id in looks_to_delete: look_updated = looker.update_look(look_id, body=soft_delete, fields='id') if look_updated: pprint("Soft deleted look id " + str(look_updated['id']))
secret = my_secret) # GET request to /looks endpoint with look id and extract the query id query_id = looker.get_look_info(look_id,"query_id") pprint(query_id) # GET request to /queries endpoint with query id from step 1 to get the query definition query = looker.get_query(query_id['query_id'],"model,view,pivots,row_total,query_timezone,limit,filters,filter_expression,fill_fields,fields,dynamic_fields,column_limit,total,sorts") pprint(query) # Modify the body of the query object to change the filter value if query['filters'][filter_field] == old_value: query['filters'][filter_field] = new_value else: print("no match") # # create a new query with the updated query object post_query = looker.create_query(query,"id") pprint(post_query) # use the new query to update a look body = {"query_id": post_query['id']} look = looker.update_look(look_id,body) pprint(look)
parser.add_argument("-l", "--looks", dest="looks",help="comma separated list of look ids") parser.add_argument("-m", "--model",dest="model",help="name of model to migrate looks to") args = parser.parse_args() 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) for look in args.looks.split(','): look_info = looker.get_look_info(look_id=look,fields='query_id') look_query_id = look_info['query_id'] query_object = looker.get_query(look_query_id,fields='view,fields,pivots,fill_fields,filters,limit,column_limit,total,row_total,vis_config,filter_config,dynamic_fields,has_table_calculations,model,query_timezone') query_object['model'] = args.model new_query = looker.create_query(query_body=query_object,fields='id') look_patch_data = {} look_patch_data["query_id"] = new_query['id'] output = looker.update_look(look,look_patch_data)