From 4b6cdbfde095e27fb0ace00b5f6e39e009674c13 Mon Sep 17 00:00:00 2001 From: Jay Rosenthal Date: Sun, 11 Aug 2024 13:55:00 -0700 Subject: [PATCH 1/4] bump version --- scripts/datasources_in_workbook.py | 28 ++++++++++++++++++++++++++++ setup.py | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 scripts/datasources_in_workbook.py diff --git a/scripts/datasources_in_workbook.py b/scripts/datasources_in_workbook.py new file mode 100644 index 00000000..4e0f8191 --- /dev/null +++ b/scripts/datasources_in_workbook.py @@ -0,0 +1,28 @@ +import requests + +# Set your Tableau Online details +server = 'https://10ay.online.tableau.com/' +site_id = 'motiveoperations' +token = +workbook_id = '1440313' # The ID of the workbook you're interested in +api_version = '3.9' + +headers = { + 'X-Tableau-Auth': token, + 'Content-Type': 'application/json' +} + + +# API endpoint to get workbook details +url = f'{server}/api/{api_version}/sites/{site_id}/workbooks/{workbook_id}/content' + +response = requests.get(url, headers=headers) +workbook = response.json() + +# Check if the response contains embedded data sources +if 'workbook' in workbook and 'connections' in workbook['workbook']: + datasources = workbook['workbook']['connections'] + for datasource in datasources: + print(f"Name: {datasource['name']}, Size: {datasource.get('size', 'N/A')} bytes") +else: + print("No embedded data sources found for this workbook.") \ No newline at end of file diff --git a/setup.py b/setup.py index eac07082..7380dd42 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ long_description=readme, long_description_content_type='text/markdown', name="tableau_utilities", - version="2.2.11", + version="2.2.12", requires_python=">=3.8", packages=[ 'tableau_utilities', From fe163f3a5b12fe421bffa4a66d0f9aab5b5487fe Mon Sep 17 00:00:00 2001 From: Jay Rosenthal Date: Sun, 11 Aug 2024 14:24:58 -0700 Subject: [PATCH 2/4] add debugging logs --- tableau_utilities/scripts/gen_config.py | 8 +++++++- tableau_utilities/scripts/merge_config.py | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tableau_utilities/scripts/gen_config.py b/tableau_utilities/scripts/gen_config.py index ab8c3673..96d93fdf 100644 --- a/tableau_utilities/scripts/gen_config.py +++ b/tableau_utilities/scripts/gen_config.py @@ -10,7 +10,7 @@ from tableau_utilities.tableau_server.tableau_server import TableauServer -def load_csv_with_definitions(file=None): +def load_csv_with_definitions(file=None, debugging_logs=False): """ Returns a dictionary with the definitions from a csv. The columns are expected to include column_name and description Args: @@ -35,6 +35,12 @@ def load_csv_with_definitions(file=None): if str(column['description']) != 'nan': definitions_mapping[column['column_name']] = column['description'] + if debugging_logs: + print(column['column_name'], column['description']) + + if debugging_logs: + print(definitions_mapping) + return definitions_mapping diff --git a/tableau_utilities/scripts/merge_config.py b/tableau_utilities/scripts/merge_config.py index 1535a55f..95f9b231 100644 --- a/tableau_utilities/scripts/merge_config.py +++ b/tableau_utilities/scripts/merge_config.py @@ -175,9 +175,17 @@ def merge_configs(args, server=None): # Merge a config with a definitions csv elif merge_with == 'csv': + # Log paths + if debugging_logs: + print(f'{color.fg_yellow}EXISTING CONFIG PATH {symbol.arrow_r} ' + f'{color.fg_grey}{existing_config}{color.reset}') + print(f'{color.fg_yellow}DEFINITIONS CSV PATH {symbol.arrow_r} ' + f'{color.fg_grey}{definitions_csv_path}{color.reset}') + # Read files existing_config = read_file(existing_config) - definitions_mapping = load_csv_with_definitions(file=definitions_csv_path) + definitions_mapping = load_csv_with_definitions(file=definitions_csv_path, debugging_logs=debugging_logs) + # Merge new_config = add_definitions_mapping(existing_config, definitions_mapping) # Sort and write the merged config From 77566034af6f58382bf0995514f8cb4661abe39e Mon Sep 17 00:00:00 2001 From: Jay Rosenthal Date: Sun, 11 Aug 2024 14:37:42 -0700 Subject: [PATCH 3/4] add debugging logs --- tableau_utilities/scripts/merge_config.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tableau_utilities/scripts/merge_config.py b/tableau_utilities/scripts/merge_config.py index 95f9b231..52b2fc6d 100644 --- a/tableau_utilities/scripts/merge_config.py +++ b/tableau_utilities/scripts/merge_config.py @@ -2,6 +2,9 @@ from tableau_utilities.general.cli_styling import Color, Symbol from tableau_utilities.scripts.gen_config import load_csv_with_definitions, generate_config +# Print Styling +color = Color() +symbol = Symbol() def read_file(file_path): """ Read a JSON file to a dictionary @@ -31,7 +34,7 @@ def write_file(file_name, config, debugging_logs=False): print('CONFIG PATH:', file_name) -def add_definitions_mapping(config, definitions_mapping): +def add_definitions_mapping(config, definitions_mapping, debugging_logs=False): """ Adds definitions from a mapping to the config. Chooses the definition from the mapping if needed Args: @@ -40,8 +43,15 @@ def add_definitions_mapping(config, definitions_mapping): """ for column, definition in definitions_mapping.items(): - if len(definition) > 0 and column in config: + has_definition = len(definition) > 0 + in_config = column in config + + if debugging_logs: + print(column, has_definition, in_config) + + if has_definition and in_config: config[column]['description'] = definition + return config @@ -165,9 +175,6 @@ def merge_configs(args, server=None): debugging_logs = args.debugging_logs existing_config = args.existing_config - # Print Styling - color = Color() - symbol = Symbol() # Merge 2 configs if merge_with == 'config': @@ -187,7 +194,7 @@ def merge_configs(args, server=None): definitions_mapping = load_csv_with_definitions(file=definitions_csv_path, debugging_logs=debugging_logs) # Merge - new_config = add_definitions_mapping(existing_config, definitions_mapping) + new_config = add_definitions_mapping(existing_config, definitions_mapping, debugging_logs) # Sort and write the merged config new_config = sort_config(new_config, debugging_logs) write_file(file_name=file_name, config=new_config, debugging_logs=debugging_logs) From df7be41f56ea89c0741284ed7e64fb6c4631736a Mon Sep 17 00:00:00 2001 From: Jay Rosenthal Date: Sun, 11 Aug 2024 14:43:23 -0700 Subject: [PATCH 4/4] delete file --- scripts/datasources_in_workbook.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 scripts/datasources_in_workbook.py diff --git a/scripts/datasources_in_workbook.py b/scripts/datasources_in_workbook.py deleted file mode 100644 index 4e0f8191..00000000 --- a/scripts/datasources_in_workbook.py +++ /dev/null @@ -1,28 +0,0 @@ -import requests - -# Set your Tableau Online details -server = 'https://10ay.online.tableau.com/' -site_id = 'motiveoperations' -token = -workbook_id = '1440313' # The ID of the workbook you're interested in -api_version = '3.9' - -headers = { - 'X-Tableau-Auth': token, - 'Content-Type': 'application/json' -} - - -# API endpoint to get workbook details -url = f'{server}/api/{api_version}/sites/{site_id}/workbooks/{workbook_id}/content' - -response = requests.get(url, headers=headers) -workbook = response.json() - -# Check if the response contains embedded data sources -if 'workbook' in workbook and 'connections' in workbook['workbook']: - datasources = workbook['workbook']['connections'] - for datasource in datasources: - print(f"Name: {datasource['name']}, Size: {datasource.get('size', 'N/A')} bytes") -else: - print("No embedded data sources found for this workbook.") \ No newline at end of file