示例#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 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")

示例#2
0
my_host = params['hosts'][source_name]['host']
my_secret = params['hosts'][source_name]['secret']
my_token = params['hosts'][source_name]['token']

dest_looker = LookerApi(host=my_host, token=my_token, secret=my_secret)

my_host = params['hosts'][destination_name]['host']
my_secret = params['hosts'][destination_name]['secret']
my_token = params['hosts'][destination_name]['token']

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 = {}
示例#3
0
# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
import http.client as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

host = 'looker'

### ------- 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)

look_id = 1
look = looker.get_look_info(look_id)
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)