diff --git a/.travis.yml b/.travis.yml index 2480df6..75674b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,4 +18,5 @@ script: # Examples - (cd "Examples/Replicate Workbook" && python replicateWorkbook.py) - (cd "Examples/List TDS Info" && python listTDSInfo.py) + - (cd "Examples/GetFields" && python show_fields.py) diff --git a/Examples/GetFields/World.tds b/Examples/GetFields/World.tds new file mode 120000 index 0000000..397f696 --- /dev/null +++ b/Examples/GetFields/World.tds @@ -0,0 +1 @@ +../List TDS Info/World.tds \ No newline at end of file diff --git a/Examples/GetFields/show_fields.py b/Examples/GetFields/show_fields.py new file mode 100644 index 0000000..b04a056 --- /dev/null +++ b/Examples/GetFields/show_fields.py @@ -0,0 +1,29 @@ +############################################################ +# Step 1) Use Datasource object from the Document API +############################################################ +from tableaudocumentapi import Datasource + +############################################################ +# 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('----------------------------------------------------------') +for count, field in enumerate(sourceTDS.fields.values()): + print('{:>4}: {} is a {}'.format(count+1, field.name, field.datatype)) + blank_line = False + if field.calculation: + print(' the formula is {}'.format(field.calculation)) + blank_line = True + if field.aggregation: + print(' the default aggregation is {}'.format(field.aggregation)) + blank_line = True + + if blank_line: + print('') +print('----------------------------------------------------------')