Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ tasks.json

#Jekyll
docs/_site

#Local venv
venv/
46 changes: 46 additions & 0 deletions samples/show-fields/fields_to_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
############################################################
# Step 1) Use Datasource object from the Document API
############################################################
from tableaudocumentapi import Datasource
import xml.etree.ElementTree as ET
import pandas as pd
from tabulate import tabulate

############################################################
# Step 2) Open the .tds we want to inspect
############################################################
sourceTDS = Datasource.from_file('world.tds')

############################################################
# Step 3) Print out all of the fields and what type they are
############################################################
print('----------------------------------------------------------')
print('--- {} total fields in this datasource'.format(len(sourceTDS.fields)))
print('----------------------------------------------------------')

field_list = []

for count, field in enumerate(sourceTDS.fields.values()):

if field.description is not None:
description_xml = ET.fromstring(field.description)
description_without_tags = description_xml[0][0].text
else:
description_without_tags = None

field_dict = {'name': field.name,
'caption': field.caption,
'role': field.role,
'type': field.type,
'datatype': field.datatype,
'calculation': field.calculation,
'default_aggregation': field.default_aggregation,
# 'description': field.description,
'description_raw': description_without_tags}


field_list.append(field_dict)

df = pd.DataFrame(field_list)
print(tabulate(df, headers='keys', tablefmt='psql'))