-
Notifications
You must be signed in to change notification settings - Fork 66
/
move_look.py
72 lines (45 loc) · 1.82 KB
/
move_look.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: UTF-8 -*-
import yaml ### YOU NEED THE pyyaml PACKAGE : [sudo] pip install pyyaml
from lookerapi import LookerApi
from pprint import pprint as pp
import json
### ------- HERE ARE PARAMETERS TO CONFIGURE -------
source_name = 'sandbox' ### The name in your config.yml file
source_look_id = 58 ### The look number you would like to move
destination_name = 'production' ### The name in your config.yml file
destination_space_id = 769 ### The destination space ID to move the look to
### ------- OPEN THE CONFIG FILE and INSTANTIATE API -------
f = open('config.yml')
params = yaml.load(f)
f.close()
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 = {}
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"