Exemple #1
0
                 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)
    "sorts": ["content_usage.days_since_last_accessed desc"],
    "limit":
    "500",
    "vis_config": {
        "table_theme":
        "white",
        "type":
        "table",
        "hidden_fields": [
            "dashboard.id", "dashboard.user_id", "dashboard.space_id",
            "look.id", "look.user_id", "look.space_id"
        ]
    }
}

content_usage_query = looker.create_query(query_body=content_usage_query_body)

print('Query Created: ' + str(content_usage_query['id']))

new_look = {}
new_look['space_id'] = space_id
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'])
Exemple #3
0
source_looker = LookerApi(host=my_host, token=my_token, secret=my_secret)

### ------- GET THE SOURCE LOOK -------

look_body = source_looker.get_look_info(source_look_id,
                                        'query_id, query, title')
print "---- Source Look Body ----"
pp(look_body)

print "---- Source query ----"
query_body = source_looker.get_query(look_body['query_id'])
pp(query_body)

### ------- BUILD THE TARGET LOOK -------

print "---- New query ----"
new_query = dest_looker.create_query(query_body, 'id')
new_query_id = str(new_query['id'])
print new_query_id + " is the new query id"

new_look = {}
new_look['space_id'] = destination_space_id
new_look['query_id'] = new_query_id
new_look['title'] = look_body['title'] + "from teach"
dest_looker.create_look(new_look)

### ------- DONE -------

print "Done"
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)