|
| 1 | +#### |
| 2 | +# Getting Started Part Three of Three |
| 3 | +# This script demonstrates all the different types of 'content' a server contains |
| 4 | +# |
| 5 | +# To make it easy to run, it doesn't take any arguments - you need to edit the code with your info |
| 6 | +#### |
| 7 | + |
| 8 | +import getpass |
| 9 | +import tableauserverclient as TSC |
| 10 | + |
| 11 | + |
| 12 | +def main(): |
| 13 | + # 1 - replace with your server url |
| 14 | + server_url = "https://10ax.online.tableau.com" |
| 15 | + |
| 16 | + # 2 - change to false **for testing only** if you get a certificate error |
| 17 | + use_ssl = True |
| 18 | + server = TSC.Server(server_url, use_server_version=True, http_options={"verify": use_ssl}) |
| 19 | + |
| 20 | + print("Connected to {}".format(server.server_info.baseurl)) |
| 21 | + |
| 22 | + # 3 - replace with your site name exactly as it looks in a url |
| 23 | + # e.g https://my-server/#/this-is-your-site-url-name/ |
| 24 | + site_url_name = "" # leave empty if there is no site name in the url (you are on the default site) |
| 25 | + |
| 26 | + # 4 |
| 27 | + username = "your-username-here" |
| 28 | + password = getpass.getpass("Your password:") # so you don't save it in this file |
| 29 | + tableau_auth = TSC.TableauAuth(username, password, site_id=site_url_name) |
| 30 | + |
| 31 | + # OR instead of username+password, use a Personal Access Token (PAT) (required by Tableau Cloud) |
| 32 | + # token_name = "your-token-name" |
| 33 | + # token_value = "your-token-value-long-random-string" |
| 34 | + # tableau_auth = TSC.PersonalAccessTokenAuth(token_name, token_value, site_id=site_url_name) |
| 35 | + |
| 36 | + with server.auth.sign_in(tableau_auth): |
| 37 | + projects, pagination = server.projects.get() |
| 38 | + if projects: |
| 39 | + print("{} projects".format(pagination.total_available)) |
| 40 | + for project in projects: |
| 41 | + print(project.name) |
| 42 | + |
| 43 | + workbooks, pagination = server.datasources.get() |
| 44 | + if workbooks: |
| 45 | + print("{} workbooks".format(pagination.total_available)) |
| 46 | + print(workbooks[0]) |
| 47 | + |
| 48 | + views, pagination = server.views.get() |
| 49 | + if views: |
| 50 | + print("{} views".format(pagination.total_available)) |
| 51 | + print(views[0]) |
| 52 | + |
| 53 | + datasources, pagination = server.datasources.get() |
| 54 | + if datasources: |
| 55 | + print("{} datasources".format(pagination.total_available)) |
| 56 | + print(datasources[0]) |
| 57 | + |
| 58 | + # I think all these other content types can go to a hello_universe script |
| 59 | + # data alert, dqw, flow, ... do any of these require any add-ons? |
| 60 | + jobs, pagination = server.jobs.get() |
| 61 | + if jobs: |
| 62 | + print("{} jobs".format(pagination.total_available)) |
| 63 | + print(jobs[0]) |
| 64 | + |
| 65 | + metrics, pagination = server.metrics.get() |
| 66 | + if metrics: |
| 67 | + print("{} metrics".format(pagination.total_available)) |
| 68 | + print(metrics[0]) |
| 69 | + |
| 70 | + schedules, pagination = server.schedules.get() |
| 71 | + if schedules: |
| 72 | + print("{} schedules".format(pagination.total_available)) |
| 73 | + print(schedules[0]) |
| 74 | + |
| 75 | + tasks, pagination = server.tasks.get() |
| 76 | + if tasks: |
| 77 | + print("{} tasks".format(pagination.total_available)) |
| 78 | + print(tasks[0]) |
| 79 | + |
| 80 | + webhooks, pagination = server.webhooks.get() |
| 81 | + if webhooks: |
| 82 | + print("{} webhooks".format(pagination.total_available)) |
| 83 | + print(webhooks[0]) |
| 84 | + |
| 85 | + users, pagination = server.metrics.get() |
| 86 | + if users: |
| 87 | + print("{} users".format(pagination.total_available)) |
| 88 | + print(users[0]) |
| 89 | + |
| 90 | + groups, pagination = server.groups.get() |
| 91 | + if groups: |
| 92 | + print("{} groups".format(pagination.total_available)) |
| 93 | + print(groups[0]) |
| 94 | + |
| 95 | + if __name__ == "__main__": |
| 96 | + main() |
0 commit comments