forked from tableau/document-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplicate_workbook.py
More file actions
25 lines (22 loc) · 1.24 KB
/
Copy pathreplicate_workbook.py
File metadata and controls
25 lines (22 loc) · 1.24 KB
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
import csv # so we can work with our database list (in a CSV file)
############################################################
# Step 1) Use Workbook object from the Document API
############################################################
from tableaudocumentapi import Workbook
############################################################
# Step 2) Open the .twb we want to replicate
############################################################
sourceWB = Workbook('sample-superstore.twb')
############################################################
# Step 3) Use a database list (in CSV), loop thru and
# create new .twb's with their settings
############################################################
with open('databases.csv') as csvfile:
databases = csv.DictReader(csvfile, delimiter=',', quotechar='"')
for row in databases:
# Set our unique values for this database
sourceWB.datasources[0].connections[0].server = row['Server']
sourceWB.datasources[0].connections[0].dbname = row['Database']
sourceWB.datasources[0].connections[0].username = row['User']
# Save our newly created .twb with the new file name
sourceWB.save_as(row['DBFriendlyName'] + ' - Superstore' + '.twb')