def list_workbook_ids(self, checkpoint: Union[datetime, str] = None, limit: int = None) -> List[str]: # Create client filter object req_option = tsc.RequestOptions() req_option.sort.add( tsc.Sort(tsc.RequestOptions.Field.UpdatedAt, tsc.RequestOptions.Direction.Asc)) if checkpoint: # Format datetime for filter if isinstance(checkpoint, datetime): cp = self.format_checkpoint_datetime(checkpoint) else: cp = self.format_checkpoint_datetime(parse(checkpoint)) req_option.filter.add( tsc.Filter(tsc.RequestOptions.Field.UpdatedAt, tsc.RequestOptions.Operator.GreaterThanOrEqual, cp)) # Get filtered id's server = self.server with server.auth.sign_in(self.authentication): workbook_ids = [ wb.id for wb in tsc.Pager(server.workbooks, req_option) ] else: # Get all workbook id's workbook_ids = self.list_all_workbook_ids() # Return, with optional applied limit if limit: return workbook_ids[:limit] else: return workbook_ids
def list_all_workbook_ids(self): # Get all WorkbookItem id's, sorted by UpdatedAt req_option = tsc.RequestOptions() req_option.sort.add( tsc.Sort(tsc.RequestOptions.Field.UpdatedAt, tsc.RequestOptions.Direction.Asc)) workbook_ids = [] server = self.server with server.auth.sign_in(self.authentication): workbook_ids = [ wb.id for wb in tsc.Pager(server.workbooks, req_option) ] return workbook_ids
def test_sort_asc(self): with requests_mock.mock() as m: m.get(requests_mock.ANY) url = "http://test/api/2.3/sites/dad65087-b08b-4603-af4e-2887b8aafc67/workbooks" opts = TSC.RequestOptions(pagesize=13, pagenumber=13) opts.sort.add( TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Asc)) resp = self.server.workbooks.get_request(url, request_object=opts) self.assertTrue(re.search("pagenumber=13", resp.request.query)) self.assertTrue(re.search("pagesize=13", resp.request.query)) self.assertTrue(re.search("sort=name%3aasc", resp.request.query))
def test_sort_asc(self): with requests_mock.mock() as m: m.get(requests_mock.ANY) url = "http://test/api/2.3/sites/dad65087-b08b-4603-af4e-2887b8aafc67/workbooks" opts = TSC.RequestOptions(pagesize=13, pagenumber=13) opts.sort.add(TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Asc)) resp = self.server.workbooks._make_request(requests.get, url, content=None, request_object=opts, auth_token='j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM', content_type='text/xml') self.assertEqual(resp.request.query, 'pagenumber=13&pagesize=13&sort=name:asc')
def test_double_query_params(self) -> None: with requests_mock.mock() as m: m.get(requests_mock.ANY) url = self.baseurl + "/views?queryParamExists=true" opts = TSC.RequestOptions() opts.filter.add( TSC.Filter(TSC.RequestOptions.Field.Tags, TSC.RequestOptions.Operator.In, ["stocks", "market"])) opts.sort.add( TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Asc)) resp = self.server.workbooks.get_request(url, request_object=opts) self.assertTrue( re.search("queryparamexists=true", resp.request.query)) self.assertTrue( re.search("filter=tags%3ain%3a%5bstocks%2cmarket%5d", resp.request.query)) self.assertTrue(re.search("sort=name%3aasc", resp.request.query))
def test_filter_sort_legacy(self): self.server.version = "3.6" with requests_mock.mock() as m: m.get(requests_mock.ANY) url = self.baseurl + "/views?queryParamExists=true" opts = TSC.RequestOptions() opts.filter.add( TSC.Filter(TSC.RequestOptions.Field.Tags, TSC.RequestOptions.Operator.In, ['stocks', 'market'])) opts.sort.add( TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Asc)) resp = self.server.workbooks.get_request(url, request_object=opts) self.assertTrue( re.search('queryparamexists=true', resp.request.query)) self.assertTrue( re.search('filter=tags:in:%5bstocks,market%5d', resp.request.query)) self.assertTrue(re.search('sort=name:asc', resp.request.query))
def main(): parser = argparse.ArgumentParser(description='Filter and sort projects.') parser.add_argument('--server', '-s', required=True, help='server address') parser.add_argument('--username', '-u', required=True, help='username to sign into server') parser.add_argument('--site', '-S', default=None) parser.add_argument('-p', default=None) parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', help='desired logging level (set to error by default)') args = parser.parse_args() if args.p is None: password = getpass.getpass("Password: "******"No project named '{}' found".format(filter_project_name) print(error) create_example_project(name='Example 1', server=server) create_example_project(name='Example 2', server=server) create_example_project(name='Example 3', server=server) create_example_project(name='Proiect ca Exemplu', server=server) options = TSC.RequestOptions() # don't forget to URL encode the query names options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.In, ['Example+1', 'Example+2', 'Example+3'])) options.sort.add(TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Desc)) matching_projects, pagination_item = server.projects.get(req_options=options) print('Filtered projects are:') for project in matching_projects: print(project.name, project.id)
def main(): parser = argparse.ArgumentParser(description='Filter on groups') parser.add_argument('--server', '-s', required=True, help='server address') parser.add_argument('--username', '-u', required=True, help='username to sign into server') parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', help='desired logging level (set to error by default)') parser.add_argument('-p', default=None) args = parser.parse_args() if args.p is None: password = getpass.getpass("Password: "******"SALES NORTHWEST" create_example_group(group_name, server) group_name = 'SALES ROMANIA' # Try to create a group named "SALES ROMANIA" create_example_group(group_name, server) # URL Encode the name of the group that we want to filter on # i.e. turn spaces into plus signs filter_group_name = 'SALES+ROMANIA' options = TSC.RequestOptions() options.filter.add( TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, filter_group_name)) filtered_groups, _ = server.groups.get(req_options=options) # Result can either be a matching group or an empty list if filtered_groups: group_name = filtered_groups.pop().name print(group_name) else: error = "No project named '{}' found".format(filter_group_name) print(error) options = TSC.RequestOptions() options.filter.add( TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.In, ['SALES+NORTHWEST', 'SALES+ROMANIA', 'this_group'])) options.sort.add( TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Desc)) matching_groups, pagination_item = server.groups.get( req_options=options) print('Filtered groups are:') for group in matching_groups: print(group.name)
ws.cell(row=1, column=7).value = 'Data Subject Type' ws.cell(row=1, column=8).value = 'Target Audience' ws.cell(row=1, column=9).value = 'Team Member' ws.cell(row=1, column=10).value = 'Data Update Frequency' ws.cell(row=1, column=11).value = 'School Filter?' ws.cell(row=1, column=12).value = 'Actions?' ws.cell(row=1, column=13).value = 'Tags' ws.cell(row=1, column=14).value = 'Dashboard Tips' ws.cell(row=1, column=15).value = 'Context and Definitions' ws.cell(row=1, column=16).value = 'Embed Code' with server.auth.sign_in(tableau_auth): req_options = TSC.RequestOptions() req_options.page_size(1000) req_options.sort.add( TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Asc)) all_views, pagination_item = server.views.get(req_options) i = 2 for view in all_views: owner = server.users.get_by_id(view.owner_id) workbook = server.workbooks.get_by_id(view.workbook_id) #only get views in KASTLE project if (workbook.project_name == 'KASTLE'): ws.cell(row=i, column=1).value = workbook.name #split workbook name into array of strings categories = workbook.name.split('_') #if there are 3 string then there is a sub category if len(categories) == 3: ws.cell(row=i, column=2).value = categories[0] ws.cell(row=i, column=3).value = categories[1]
def main(): parser = argparse.ArgumentParser(description="Filter and sort projects.") # Common options; please keep those in sync across all samples parser.add_argument("--server", "-s", required=True, help="server address") parser.add_argument("--site", "-S", help="site name") parser.add_argument( "--token-name", "-p", required=True, help="name of the personal access token used to sign into the server") parser.add_argument( "--token-value", "-v", required=True, help="value of the personal access token used to sign into the server") parser.add_argument( "--logging-level", "-l", choices=["debug", "info", "error"], default="error", help="desired logging level (set to error by default)", ) # Options specific to this sample # This sample has no additional options, yet. If you add some, please add them here args = parser.parse_args() # Set logging level based on user input, or error by default logging_level = getattr(logging, args.logging_level.upper()) logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): # Use highest Server REST API version available server.use_server_version() filter_project_name = "default" options = TSC.RequestOptions() options.filter.add( TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, filter_project_name)) filtered_projects, _ = server.projects.get(req_options=options) # Result can either be a matching project or an empty list if filtered_projects: project_name = filtered_projects.pop().name print(project_name) else: error = "No project named '{}' found".format(filter_project_name) print(error) create_example_project(name="Example 1", server=server) create_example_project(name="Example 2", server=server) create_example_project(name="Example 3", server=server) create_example_project(name="Proiect ca Exemplu", server=server) options = TSC.RequestOptions() # don't forget to URL encode the query names options.filter.add( TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.In, ["Example+1", "Example+2", "Example+3"])) options.sort.add( TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Desc)) matching_projects, pagination_item = server.projects.get( req_options=options) print("Filtered projects are:") for project in matching_projects: print(project.name, project.id) # Or, try the django style filtering. projects = ["Example 1", "Example 2", "Example 3"] projects = [urllib.parse.quote_plus(p) for p in projects] for project in server.projects.filter(name__in=projects).sort("-name"): print(project.name, project.id)
def main(): parser = argparse.ArgumentParser( description="List out the names and LUIDs for different resource types." ) # Common options; please keep those in sync across all samples parser.add_argument("--server", "-s", required=True, help="server address") parser.add_argument("--site", "-S", help="site name") parser.add_argument( "--token-name", "-n", required=True, help="name of the personal access token used to sign into the server") parser.add_argument( "--token-value", "-v", required=True, help="value of the personal access token used to sign into the server") parser.add_argument( "--logging-level", "-l", choices=["debug", "info", "error"], default="error", help="desired logging level (set to error by default)", ) # Options specific to this sample parser.add_argument("resource_type", choices=[ "workbook", "datasource", "project", "view", "job", "webhooks" ]) args = parser.parse_args() # Set logging level based on user input, or error by default logging_level = getattr(logging, args.logging_level.upper()) logging.basicConfig(level=logging_level) # Sign in to server tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): endpoint = { "datasource": server.datasources, "job": server.jobs, "metric": server.metrics, "project": server.projects, "view": server.views, "webhooks": server.webhooks, "workbook": server.workbooks, }.get(args.resource_type) options = TSC.RequestOptions() options.sort.add( TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Desc)) count = 0 for resource in TSC.Pager(endpoint.get, options): count = count + 1 print(resource.id, resource.name) print("Total: {}".format(count))
def main(): parser = argparse.ArgumentParser(description="Filter and sort groups.") # Common options; please keep those in sync across all samples parser.add_argument("--server", "-s", required=True, help="server address") parser.add_argument("--site", "-S", help="site name") parser.add_argument( "--token-name", "-p", required=True, help="name of the personal access token used to sign into the server") parser.add_argument( "--token-value", "-v", required=True, help="value of the personal access token used to sign into the server") parser.add_argument( "--logging-level", "-l", choices=["debug", "info", "error"], default="error", help="desired logging level (set to error by default)", ) # Options specific to this sample # This sample has no additional options, yet. If you add some, please add them here args = parser.parse_args() # Set logging level based on user input, or error by default logging_level = getattr(logging, args.logging_level.upper()) logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): group_name = "SALES NORTHWEST" # Try to create a group named "SALES NORTHWEST" create_example_group(group_name, server) group_name = "SALES ROMANIA" # Try to create a group named "SALES ROMANIA" create_example_group(group_name, server) # URL Encode the name of the group that we want to filter on # i.e. turn spaces into plus signs filter_group_name = urllib.parse.quote_plus(group_name) options = TSC.RequestOptions() options.filter.add( TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, filter_group_name)) filtered_groups, _ = server.groups.get(req_options=options) # Result can either be a matching group or an empty list if filtered_groups: group_name = filtered_groups.pop().name print(group_name) else: error = "No project named '{}' found".format(filter_group_name) print(error) # Or, try the above with the django style filtering try: group = server.groups.filter(name=filter_group_name)[0] except IndexError: print(f"No project named '{filter_group_name}' found") else: print(group.name) options = TSC.RequestOptions() options.filter.add( TSC.Filter( TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.In, ["SALES+NORTHWEST", "SALES+ROMANIA", "this_group"], )) options.sort.add( TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Desc)) matching_groups, pagination_item = server.groups.get( req_options=options) print("Filtered groups are:") for group in matching_groups: print(group.name) # or, try the above with the django style filtering. groups = ["SALES NORTHWEST", "SALES ROMANIA", "this_group"] groups = [urllib.parse.quote_plus(group) for group in groups] for group in server.groups.filter(name__in=groups).sort("-name"): print(group.name)
def main(): parser = argparse.ArgumentParser(description='Filter and sort projects.') # Common options; please keep those in sync across all samples parser.add_argument('--server', '-s', required=True, help='server address') parser.add_argument('--site', '-S', help='site name') parser.add_argument( '--token-name', '-p', required=True, help='name of the personal access token used to sign into the server') parser.add_argument( '--token-value', '-v', required=True, help='value of the personal access token used to sign into the server') parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', help='desired logging level (set to error by default)') # Options specific to this sample # This sample has no additional options, yet. If you add some, please add them here args = parser.parse_args() # Set logging level based on user input, or error by default logging_level = getattr(logging, args.logging_level.upper()) logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): # Use highest Server REST API version available server.use_server_version() filter_project_name = 'default' options = TSC.RequestOptions() options.filter.add( TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, filter_project_name)) filtered_projects, _ = server.projects.get(req_options=options) # Result can either be a matching project or an empty list if filtered_projects: project_name = filtered_projects.pop().name print(project_name) else: error = "No project named '{}' found".format(filter_project_name) print(error) create_example_project(name='Example 1', server=server) create_example_project(name='Example 2', server=server) create_example_project(name='Example 3', server=server) create_example_project(name='Proiect ca Exemplu', server=server) options = TSC.RequestOptions() # don't forget to URL encode the query names options.filter.add( TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.In, ['Example+1', 'Example+2', 'Example+3'])) options.sort.add( TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Desc)) matching_projects, pagination_item = server.projects.get( req_options=options) print('Filtered projects are:') for project in matching_projects: print(project.name, project.id)
def main(): parser = argparse.ArgumentParser(description='Filter and sort groups.') # Common options; please keep those in sync across all samples parser.add_argument('--server', '-s', required=True, help='server address') parser.add_argument('--site', '-S', help='site name') parser.add_argument( '--token-name', '-p', required=True, help='name of the personal access token used to sign into the server') parser.add_argument( '--token-value', '-v', required=True, help='value of the personal access token used to sign into the server') parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', help='desired logging level (set to error by default)') # Options specific to this sample # This sample has no additional options, yet. If you add some, please add them here args = parser.parse_args() # Set logging level based on user input, or error by default logging_level = getattr(logging, args.logging_level.upper()) logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server, use_server_version=True) with server.auth.sign_in(tableau_auth): group_name = 'SALES NORTHWEST' # Try to create a group named "SALES NORTHWEST" create_example_group(group_name, server) group_name = 'SALES ROMANIA' # Try to create a group named "SALES ROMANIA" create_example_group(group_name, server) # URL Encode the name of the group that we want to filter on # i.e. turn spaces into plus signs filter_group_name = 'SALES+ROMANIA' options = TSC.RequestOptions() options.filter.add( TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, filter_group_name)) filtered_groups, _ = server.groups.get(req_options=options) # Result can either be a matching group or an empty list if filtered_groups: group_name = filtered_groups.pop().name print(group_name) else: error = "No project named '{}' found".format(filter_group_name) print(error) options = TSC.RequestOptions() options.filter.add( TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.In, ['SALES+NORTHWEST', 'SALES+ROMANIA', 'this_group'])) options.sort.add( TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Desc)) matching_groups, pagination_item = server.groups.get( req_options=options) print('Filtered groups are:') for group in matching_groups: print(group.name)