Skip to content

Commit

Permalink
Updated README to reflect new file swapping argument on TableauDocume…
Browse files Browse the repository at this point in the history
…nt.save_new_file
  • Loading branch information
Bryant Howell committed Apr 15, 2019
1 parent 7de408d commit 8787fc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The TableauDatasource class uses the `TDEFileGenerator` and/or the `HyperFileGen
* 4.5.0: 2018.1 (API 3.0) compatibility. All requests for a given connection using a single HTTP session, and other improvements to the RestXmlRequest class.
* 4.7.0: Dropping API 2.0 (Tableau 9.0) compatibility. Any method that is overwritten in a later version will not be updated in the TableauRestApiConnection class going forward. Also implemented a direct_xml_request parameter for Add and Update methods, allowing direct submission of an ElementTree.Element request to the endpoints, particularly for replication.
* 4.8.0 Introduces the RestJsonRequest object and _json plural querying methods for passing JSON responses to other systems
* 4.9.0 API 3.3 (2019.1) compatibility, as well as ability to swap in static files using TableauDocument and other bug fixes.
## --- Table(au) of Contents ---
------

Expand Down Expand Up @@ -1121,6 +1122,23 @@ ex.
print(file_2)
# u'A Workbook (2).twb'

#### 2.2.1 Replacing Static Data Files
`TableauFile` has an optional argument on the save_new_file method to allow swapping in new data files (CSV, XLS or Hyper) into an existing TWBX or TDSX.

TableauFile.save_new_file(new_filename_no_extension, data_file_replacement_map=None) # returns new filename

data_file_replacement_map accepts a dict in format { 'TableauFileFilename' : 'FilenameOfNewFileOnDisk' }. To find out the TableauFileFilename, print out the `other_files` property of the TableauFile object:

t_file = TableauFile('My AmazingWorkbook.twbx')
for file in t_file.other_files:
print(file)
You should be able to find the exact naming of the data file you want to replace. Copy that exactly and use it as the key in your dictionary. For the value, use a fully qualified filename on your machine:

t_file = TableauFile('My AmazingWorkbook.twbx')
file_map = { 'Data/en_US-US/Sample - Superstore.xls' : '/Users/bhowell/Documents/My Tableau Repository/Datasources/2018.3/en_US-EU/Sample - EU Superstore.xls'}
t_file.save_new_file('My AmazingWorkbook - Updated', data_file_replacement_map=file_map)

### 2.3 TableauDocument Class
The TableauDocument class helps map the differences between `TableauWorkbook` and `TableauDatasource`. It only implements two properties:

Expand Down
2 changes: 1 addition & 1 deletion tableau_documents/tableau_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def save_new_file(self, new_filename_no_extension, data_file_replacement_map=Non
try:
shutil.rmtree(directory)
except OSError as e:
# Just means that directory didn't exist for some reason, probably a swap occurred
# Just means that directory didn't exist for some reason, probably a swap occurred
pass
new_zf.close()

Expand Down

0 comments on commit 8787fc3

Please sign in to comment.