-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-connections.py
38 lines (33 loc) · 1.18 KB
/
update-connections.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
from tableaudocumentapi import Workbook
wb = Workbook('./assets/workbooks/Superstore.twbx')
ds = wb.datasources
conns = ds.connections
class ConnectionObj:
"""An object used to update datasource connection attributes"""
def __init__(self, svr, dbn, usr, dbc, prt, qrb, sql):
self.server = svr
self.dbname = dbn
self.username = usr
self.dbclass = dbc
self.port = prt
self.query_band = qrb
self.initial_sql = sql
def updateConnection(connection, ConnectionObj):
# checks for empty connection objects
try:
type(connection) is not None
except ValueError:
print('This connection does not have a connection object!')
# checks for missing object used to update connections
try:
type(ConnectionObj) is not None
except ValueError:
print('No ConnectionObj provided!')
connection.server = ConnectionObj.server
connection.dbname = ConnectionObj.dbname
connection.username = ConnectionObj.username
connection.dbclass = ConnectionObj.dbclass
connection.port = ConnectionObj.port
connection.query_band = ConnectionObj.query_band
connection.initial_sql = ConnectionObj.initial_sql
conn1 = ConnectionObj('none', 'Sales Target (US)', 'Johnny Viz', '')