From 9437e79921e92dab5a253873a7d4d01bbabd8cf0 Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Mon, 11 Jul 2016 09:46:58 -0700 Subject: [PATCH 1/5] Get Fields Example Code --- Examples/GetFields/World.tds | 1 + Examples/GetFields/show_fields.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 120000 Examples/GetFields/World.tds create mode 100644 Examples/GetFields/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..a55c163 --- /dev/null +++ b/Examples/GetFields/show_fields.py @@ -0,0 +1,27 @@ +############################################################ +# Step 1) Use Datasource object from the Document API +############################################################ +from tableaudocumentapi import Datasource + +############################################################ +# Step 2) Open the .tds we want to replicate +############################################################ +sourceTDS = Datasource.from_file('World.tds') + +############################################################ +# Step 3) Print out all of the fields and what type they are +############################################################ +print('----------------------------------------------------------') +for field_key, field in sourceTDS.fields.items(): + print('{} is a {}'.format(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('----------------------------------------------------------') From c389609d1cf7c59c5496961c328fe1d31ebffe04 Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Mon, 11 Jul 2016 10:07:50 -0700 Subject: [PATCH 2/5] Adding field count and numbering --- Examples/GetFields/show_fields.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Examples/GetFields/show_fields.py b/Examples/GetFields/show_fields.py index a55c163..22819d3 100644 --- a/Examples/GetFields/show_fields.py +++ b/Examples/GetFields/show_fields.py @@ -12,14 +12,18 @@ # 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('----------------------------------------------------------') +count = 0 for field_key, field in sourceTDS.fields.items(): - print('{} is a {}'.format(field.name, field.datatype)) + count += 1 + print('{:>4}: {} is a {}'.format(count, field.name, field.datatype)) blank_line = False if field.calculation: - print('--- the formula is {}'.format(field.calculation)) + print(' the formula is {}'.format(field.calculation)) blank_line = True if field.aggregation: - print('--- the default aggregation is {}'.format(field.aggregation)) + print(' the default aggregation is {}'.format(field.aggregation)) blank_line = True if blank_line: From d376c3adf44ece2649d652cccdeece922a31d136 Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Mon, 11 Jul 2016 10:35:00 -0700 Subject: [PATCH 3/5] updating comment to be accurate --- Examples/GetFields/show_fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/GetFields/show_fields.py b/Examples/GetFields/show_fields.py index 22819d3..6e77712 100644 --- a/Examples/GetFields/show_fields.py +++ b/Examples/GetFields/show_fields.py @@ -4,7 +4,7 @@ from tableaudocumentapi import Datasource ############################################################ -# Step 2) Open the .tds we want to replicate +# Step 2) Open the .tds we want to inspect ############################################################ sourceTDS = Datasource.from_file('World.tds') From fa7ca5aa7ba3f2a0eb6613df99fa795972ec3c8d Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Mon, 11 Jul 2016 13:45:41 -0700 Subject: [PATCH 4/5] Adding GetFields to travis run --- .travis.yml | 1 + 1 file changed, 1 insertion(+) 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) From 9ab86d04bfe7386976cc34c7dc4a21295ec5413a Mon Sep 17 00:00:00 2001 From: Russell Hay Date: Mon, 11 Jul 2016 13:47:29 -0700 Subject: [PATCH 5/5] Updating to use enumerate to keep track of count --- Examples/GetFields/show_fields.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Examples/GetFields/show_fields.py b/Examples/GetFields/show_fields.py index 6e77712..b04a056 100644 --- a/Examples/GetFields/show_fields.py +++ b/Examples/GetFields/show_fields.py @@ -14,10 +14,8 @@ print('----------------------------------------------------------') print('--- {} total fields in this datasource'.format(len(sourceTDS.fields))) print('----------------------------------------------------------') -count = 0 -for field_key, field in sourceTDS.fields.items(): - count += 1 - print('{:>4}: {} is a {}'.format(count, field.name, field.datatype)) +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))