Skip to content

Update samples for Python 3.x compatibility #1479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions samples/extracts.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
####
# This script demonstrates how to use the Tableau Server Client
# to interact with workbooks. It explores the different
# functions that the Server API supports on workbooks.
#
# With no flags set, this sample will query all workbooks,
# pick one workbook and populate its connections/views, and update
# the workbook. Adding flags will demonstrate the specific feature
# on top of the general operations.
####
# This script demonstrates how to use the Tableau Server Client to interact with extracts.
# It explores the different functions that the REST API supports on extracts.
#####

import argparse
import logging
Expand Down
21 changes: 12 additions & 9 deletions samples/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
import argparse
import getpass
import logging
import os

import tableauserverclient as TSC
import env


def get_env(key):
if key in os.environ:
return os.environ[key]
return None


# If a sample has additional arguments, then it should copy this code and insert them after the call to
Expand All @@ -20,13 +26,13 @@ def set_up_and_log_in():
sample_define_common_options(parser)
args = parser.parse_args()
if not args.server:
args.server = env.server
args.server = get_env("SERVER")
if not args.site:
args.site = env.site
args.site = get_env("SITE")
if not args.token_name:
args.token_name = env.token_name
args.token_name = get_env("TOKEN_NAME")
if not args.token_value:
args.token_value = env.token_value
args.token_value = get_env("TOKEN_VALUE")
args.logging_level = "debug"

server = sample_connect_to_server(args)
Expand Down Expand Up @@ -79,10 +85,7 @@ def sample_connect_to_server(args):
# Make sure we use an updated version of the rest apis, and pass in our cert handling choice
server = TSC.Server(args.server, use_server_version=True, http_options={"verify": check_ssl_certificate})
server.auth.sign_in(tableau_auth)
server.version = "2.6"
new_site: TSC.SiteItem = TSC.SiteItem("cdnear", content_url=env.site)
server.auth.switch_site(new_site)
print("Logged in successfully")
server.version = "3.19"

return server

Expand Down
23 changes: 15 additions & 8 deletions samples/publish_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
import argparse
import logging

import os
import tableauserverclient as TSC

import env
import tableauserverclient.datetime_helpers


def get_env(key):
if key in os.environ:
return os.environ[key]
return None


def main():
parser = argparse.ArgumentParser(description="Publish a datasource to server.")
# Common options; please keep those in sync across all samples
Expand All @@ -52,13 +57,13 @@ def main():

args = parser.parse_args()
if not args.server:
args.server = env.server
args.server = get_env("SERVER")
if not args.site:
args.site = env.site
args.site = get_env("SITE")
if not args.token_name:
args.token_name = env.token_name
args.token_name = get_env("TOKEN_NAME")
if not args.token_value:
args.token_value = env.token_value
args.token_value = get_env("TOKEN_VALUE")
args.logging = "debug"
args.file = "C:/dev/tab-samples/5M.tdsx"
args.async_ = True
Expand Down Expand Up @@ -118,8 +123,10 @@ def main():
new_datasource, args.file, publish_mode, connection_credentials=new_conn_creds
)
print(
"{}Datasource published. Datasource ID: {}".format(
new_datasource.id, tableauserverclient.datetime_helpers.timestamp()
(
"{}Datasource published. Datasource ID: {}".format(
new_datasource.id, tableauserverclient.datetime_helpers.timestamp()
)
)
)
print("\t\tClosing connection")
Expand Down
2 changes: 1 addition & 1 deletion samples/set_refresh_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def usage(args):

def make_filter(**kwargs):
options = TSC.RequestOptions()
for item, value in kwargs.items():
for item, value in list(kwargs.items()):
name = getattr(TSC.RequestOptions.Field, item)
options.filter.add(TSC.Filter(name, TSC.RequestOptions.Operator.Equals, value))
return options
Expand Down
2 changes: 1 addition & 1 deletion samples/update_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def main():
update_function = endpoint.update_connection
resource = endpoint.get_by_id(args.resource_id)
endpoint.populate_connections(resource)
connections = list(filter(lambda x: x.id == args.connection_id, resource.connections))
connections = list([x for x in resource.connections if x.id == args.connection_id])
assert len(connections) == 1
connection = connections[0]
connection.username = args.datasource_username
Expand Down
109 changes: 0 additions & 109 deletions samples/update_workbook_data_acceleration.py

This file was deleted.

Loading