10000 TSC-152 #time 6h fixing quotation escaping that was causing xml to co… · onware/document-api-python@6792b1a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6792b1a

Browse files
author
Sam Bao
committed
TSC-152 #time 6h fixing quotation escaping that was causing xml to corrupt
1 parent fc6aea6 commit 6792b1a

File tree

9 files changed

+22511
-40
lines changed

9 files changed

+22511
-40
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"CurrentProjectSetting": null
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ExpandedNodes": [
3+
""
4+
],
5+
"PreviewInSolutionExplorer": false
6+
}
Binary file not shown.
76 KB
Binary file not shown.
Binary file not shown.
Loading
Loading

samples/filter-and-replicate/Zip/Job Time.twb

Lines changed: 22473 additions & 0 deletions
Large diffs are not rendered by default.

samples/filter-and-replicate/filter-and-replicate.py

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def list_files(dir):
2828
r.append(subdir + "/" + file)
2929
return r
3030

31+
3132
def main():
3233

3334
parser = argparse.ArgumentParser(description='Publish a workbook to server.')
@@ -59,13 +60,13 @@ def main():
5960
print("Total file count: " + str(total))
6061
databases = csv.DictReader(csvfile, delimiter=',', quotechar='"')
6162
for row in databases:
62-
count = count +1
63+
6364
print ("working on item: "+ str(count)+" \n")
6465
# Open the workbook
6566
source = "Source"
6667
zip = "Zip"
6768
export = "Export"
68-
69+
count = count +1
6970

7071
if(row['Format'] == ".twbx"):
7172
originaltableauworkbook = zipfile.ZipFile(os.path.join(source, row['Workbook'] + ".twbx"))
@@ -75,22 +76,22 @@ def main():
7576
for item in test:
7677
if item.endswith(".twb") :
7778
sourceWB = Workbook(os.path.join(zip, item))
78-
79-
# Update the filters
8079
for datasource in reversed(sourceWB.datasources):
81-
for children in datasource._datasourceTree._root._children:
80+
# Update the filters
81+
for children in datasource._datasourceXML._children:
8282
if "column" in children.attrib and "class" in children.attrib:
8383
if children.attrib["column"] == "[Branch]" and children.attrib["class"] == "categorical":
8484
for subchildren in children._children:
8585
if "member" in subchildren.attrib:
86-
subchildren.attrib["member"] = '"' + row['Branch'] + '"'
86+
subchildren.attrib["member"] = '"' + row['Branch'] + '"'
87+
8788

8889
# Save our newly created workbook with the new file name
8990
outputpath = os.path.join(export, row['Workbook'] + ' - ' + row['Branch'] + ".twb")
9091
sourceWB.save_as(outputpath)
9192

9293
if(row['Format'] == ".twbx"):
93-
z = zipfile.ZipFile(os.path.join(export, row['Workbook'] + ' - ' + row['Branch'] + row['Format']),mode='w')
94+
z = zipfile.ZipFile(os.path.join(export, row['Workbook'] + ' - ' + row['Branch'] + row['Format']),mode='w',compression=zipfile.ZIP_DEFLATED)
9495
z.write(os.path.join(export, row['Workbook'] + ' - ' + row['Branch'] + ".twb"),item.replace("Export",""))
9596
for item in list_files(zip):
9697
if item.endswith(".twb") != True:
@@ -107,45 +108,33 @@ def main():
107108
if children.attrib["column"] == "[Branch]" and children.attrib["class"] == "categorical":
108109
for subchildren in children._children:
109110
if "member" in subchildren.attrib:
110-
subchildren.attrib["member"] = '"' + row['Branch'] + '"'
111+
subchildren.attrib["member"] = '"' + row['Branch'] + '"'
111112

112-
# Save our newly created workbook with the new file name
113-
outputpath = os.path.join(export, row['Workbook'] + ' - ' + row['Branch'] + ".twb")
114-
sourceWB.save_as(outputpath)
115-
116-
117-
all_projects, pagination_item = server.projects.get()
118-
default_project = next((project for project in all_projects if project.name == row['Project']), None)
119-
120-
121-
connection = ConnectionItem()
122-
connection.server_address = "10ay.online.tableau.com"
123-
connection.server_port = "443"
124-
connection.connection_credentials = ConnectionCredentials(args.username, password, True)
125-
126-
all_connections = list()
127-
all_connections.append(connection)
128-
129-
if default_project is not None:
130-
new_workbook = TSC.WorkbookItem(default_project.id)
131-
if args.as_job:
132-
new_job = server.workbooks.publish(new_workbook,os.path.join(export, row['Workbook'] + ' - ' + row['Branch'] + row['Format']), overwrite_true)
133-
print("Workbook published. JOB ID: {0}".format(new_job.id))
134-
else:
135-
new_workbook = server.workbooks.publish(new_workbook, os.path.join(export, row['Workbook'] + ' - ' + row['Branch'] + row['Format']), overwrite_true)
136-
print("Workbook published. ID: {0}".format(new_workbook.id))
113+
# Save our newly created workbook with the new file name
114+
outputpath = os.path.join(export, row['Workbook'] + ' - ' + row['Branch'] + ".twb")
115+
sourceWB.save_as(outputpath)
116+
117+
118+
all_projects, pagination_item = server.projects.get()
119+
default_project = next((project for project in all_projects if project.name == row['Project']), None)
120+
121+
if default_project is not None:
122+
new_workbook = TSC.WorkbookItem(default_project.id)
123+
if args.as_job:
124+
new_job = server.workbooks.publish(new_workbook,os.path.join(export, row['Workbook'] + ' - ' + row['Branch'] + row['Format']), overwrite_true)
125+
print("Workbook published. JOB ID: {0}".format(new_job.id))
137126
else:
138-
error = "The default project could not be found."
139-
raise LookupError(error)
127+
new_workbook = server.workbooks.publish(new_workbook, os.path.join(export, row['Workbook'] + ' - ' + row['Branch'] + row['Format']), overwrite_true)
128+
print("Workbook published. ID: {0}".format(new_workbook.id))
129+
else:
130+
error = "The default project could not be found."
131+
raise LookupError(error)
140132
print ("Done!!!!!!!!!!!!!!!!!!")
141-
142-
143-
144-
133+
134+
145135
if __name__ == '__main__':
146136
main()
147137

148138

149139

150140

151-

0 commit comments

Comments
 (0)
0