From 4d332c3747df0afc6c0f884815eed2caa60cab3d Mon Sep 17 00:00:00 2001 From: jaybythebay Date: Tue, 1 Mar 2022 00:44:43 -0800 Subject: [PATCH 1/2] fidgeting with code to get raw string description without tags --- samples/show-fields/show_fields.py | 44 ++++++++++++++++++++++-------- tableaudocumentapi/field.py | 2 ++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/samples/show-fields/show_fields.py b/samples/show-fields/show_fields.py index 84cdd44..8a75af8 100644 --- a/samples/show-fields/show_fields.py +++ b/samples/show-fields/show_fields.py @@ -2,6 +2,9 @@ # Step 1) Use Datasource object from the Document API ############################################################ from tableaudocumentapi import Datasource +import lxml.etree +from xml.etree import ElementTree, ElementInclude +import xml.etree.ElementTree as ET ############################################################ # Step 2) Open the .tds we want to inspect @@ -15,17 +18,34 @@ 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.default_aggregation: - print(' the default aggregation is {}'.format(field.default_aggregation)) - blank_line = True - if field.description: - print(' the description is {}'.format(field.description)) + print(type(field)) - if blank_line: - print('') + # print(field.name) + # # print(field.datatype) + # # print(field.role) + print(field.type) + # if field.description is not None: + # print(field.description.tag) + # # This will get the raw description from an element + # print(field.description[0][0]) + # else: + # print("No Description") + + # print(type(field.description)) + print('-' * 80) + + + # 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.default_aggregation: + # print(' the default aggregation is {}'.format(field.default_aggregation)) + # blank_line = True + # if field.description: + # print(' the description is {}'.format(field.description)) + # + # if blank_line: + # print('') print('----------------------------------------------------------') diff --git a/tableaudocumentapi/field.py b/tableaudocumentapi/field.py index 88d5b3b..33e55a8 100644 --- a/tableaudocumentapi/field.py +++ b/tableaudocumentapi/field.py @@ -358,6 +358,7 @@ def _read_calculation(xmldata): @staticmethod def _read_description(xmldata): description = xmldata.find('.//desc') + # description = xmldata.find('.//run') if description is None: return None @@ -367,3 +368,4 @@ def _read_description(xmldata): description_string = description_string.decode('utf-8') return description_string + # return description From d40c02a5b85df9ba07000653a6aea45e419e42ed Mon Sep 17 00:00:00 2001 From: jaybythebay Date: Tue, 1 Mar 2022 00:58:33 -0800 Subject: [PATCH 2/2] change dash --- samples/show-fields/show_fields.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/show-fields/show_fields.py b/samples/show-fields/show_fields.py index 8a75af8..8a90758 100644 --- a/samples/show-fields/show_fields.py +++ b/samples/show-fields/show_fields.py @@ -32,7 +32,8 @@ # print("No Description") # print(type(field.description)) - print('-' * 80) + print('-' * 70) + # print('{:>4}: {} is a {}'.format(count+1, field.name, field.datatype))