@@ -36,9 +36,16 @@ def main():
3636 help = "desired logging level (set to error by default)" ,
3737 )
3838 # Options specific to this sample
39+ group = parser .add_mutually_exclusive_group (required = False )
40+ group .add_argument ("--thumbnails-user-id" , "-u" , help = "User ID to use for thumbnails" )
41+ group .add_argument ("--thumbnails-group-id" , "-g" , help = "Group ID to use for thumbnails" )
42+
43+ parser .add_argument ("--workbook-name" , "-n" , help = "Name with which to publish the workbook" )
3944 parser .add_argument ("--file" , "-f" , help = "local filepath of the workbook to publish" )
4045 parser .add_argument ("--as-job" , "-a" , help = "Publishing asynchronously" , action = "store_true" )
4146 parser .add_argument ("--skip-connection-check" , "-c" , help = "Skip live connection check" , action = "store_true" )
47+ parser .add_argument ("--project" , help = "Project within which to publish the workbook" )
48+ parser .add_argument ("--show-tabs" , help = "Publish workbooks with tabs displayed" , action = "store_true" )
4249
4350 args = parser .parse_args ()
4451
@@ -48,11 +55,22 @@ def main():
4855
4956 # Step 1: Sign in to server.
5057 tableau_auth = TSC .PersonalAccessTokenAuth (args .token_name , args .token_value , site_id = args .site )
51- server = TSC .Server (args .server , use_server_version = True )
58+ server = TSC .Server (args .server , use_server_version = True , http_options = { "verify" : False } )
5259 with server .auth .sign_in (tableau_auth ):
53- # Step 2: Get all the projects on server, then look for the default one.
54- all_projects , pagination_item = server .projects .get ()
55- default_project = next ((project for project in all_projects if project .is_default ()), None )
60+ # Step2: Retrieve the project id, if a project name was passed
61+ if args .project is not None :
62+ req_options = TSC .RequestOptions ()
63+ req_options .filter .add (
64+ TSC .Filter (TSC .RequestOptions .Field .Name , TSC .RequestOptions .Operator .Equals , args .project )
65+ )
66+ projects = list (TSC .Pager (server .projects , req_options ))
67+ if len (projects ) > 1 :
68+ raise ValueError ("The project name is not unique" )
69+ project_id = projects [0 ].id
70+ else :
71+ # Get all the projects on server, then look for the default one.
72+ all_projects , pagination_item = server .projects .get ()
73+ project_id = next ((project for project in all_projects if project .is_default ()), None ).id
5674
5775 connection1 = ConnectionItem ()
5876 connection1 .server_address = "mssql.test.com"
@@ -67,10 +85,16 @@ def main():
6785 all_connections .append (connection1 )
6886 all_connections .append (connection2 )
6987
70- # Step 3: If default project is found, form a new workbook item and publish.
88+ # Step 3: Form a new workbook item and publish.
7189 overwrite_true = TSC .Server .PublishMode .Overwrite
72- if default_project is not None :
73- new_workbook = TSC .WorkbookItem (default_project .id )
90+ if project_id is not None :
91+ new_workbook = TSC .WorkbookItem (
92+ project_id = project_id ,
93+ name = args .workbook_name ,
94+ show_tabs = args .show_tabs ,
95+ thumbnails_user_id = args .thumbnails_user_id ,
96+ thumbnails_group_id = args .thumbnails_group_id ,
97+ )
7498 if args .as_job :
7599 new_job = server .workbooks .publish (
76100 new_workbook ,
@@ -92,7 +116,7 @@ def main():
92116 )
93117 print (f"Workbook published. ID: { new_workbook .id } " )
94118 else :
95- error = "The default project could not be found."
119+ error = "The destination project could not be found."
96120 raise LookupError (error )
97121
98122
0 commit comments