@@ -40,10 +40,13 @@ def main():
4040 group .add_argument (
4141 "--csv" , dest = "type" , action = "store_const" , const = ("populate_csv" , "CSVRequestOptions" , "csv" , "csv" )
4242 )
43+ # other options shown in explore_workbooks: workbook.download, workbook.preview_image
44+
45+ parser .add_argument ("--workbook" , action = "store_true" )
4346
4447 parser .add_argument ("--file" , "-f" , help = "filename to store the exported data" )
4548 parser .add_argument ("--filter" , "-vf" , metavar = "COLUMN:VALUE" , help = "View filter to apply to the view" )
46- parser .add_argument ("resource_id" , help = "LUID for the view" )
49+ parser .add_argument ("resource_id" , help = "LUID for the view or workbook " )
4750
4851 args = parser .parse_args ()
4952
@@ -52,34 +55,46 @@ def main():
5255 logging .basicConfig (level = logging_level )
5356
5457 tableau_auth = TSC .PersonalAccessTokenAuth (args .token_name , args .token_value , site_id = args .site )
55- server = TSC .Server (args .server , use_server_version = True )
58+ server = TSC .Server (args .server , use_server_version = True , http_options = { "verify" : False } )
5659 with server .auth .sign_in (tableau_auth ):
57- views = filter (lambda x : x .id == args .resource_id or x .name == args .resource_id , TSC .Pager (server .views .get ))
58- view = list (views ).pop () # in python 3 filter() returns a filter object
60+ print ("Connected" )
61+ if args .workbook :
62+ item = server .workbooks .get_by_id (args .resource_id )
63+ else :
64+ item = server .views .get_by_id (args .resource_id )
65+
66+ if not item :
67+ print ("No item found for id {}" .format (args .resource_id ))
68+ exit (1 )
5969
70+ print ("Item found: {}" .format (item .name ))
6071 # We have a number of different types and functions for each different export type.
6172 # We encode that information above in the const=(...) parameter to the add_argument function to make
6273 # the code automatically adapt for the type of export the user is doing.
6374 # We unroll that information into methods we can call, or objects we can create by using getattr()
6475 (populate_func_name , option_factory_name , member_name , extension ) = args .type
6576 populate = getattr (server .views , populate_func_name )
77+ if args .workbook :
78+ populate = getattr (server .workbooks , populate_func_name )
79+
6680 option_factory = getattr (TSC , option_factory_name )
6781
6882 if args .filter :
6983 options = option_factory ().vf (* args .filter .split (":" ))
7084 else :
7185 options = None
86+
7287 if args .file :
7388 filename = args .file
7489 else :
7590 filename = "out.{}" .format (extension )
7691
77- populate (view , options )
92+ populate (item , options )
7893 with open (filename , "wb" ) as f :
7994 if member_name == "csv" :
80- f .writelines (getattr (view , member_name ))
95+ f .writelines (getattr (item , member_name ))
8196 else :
82- f .write (getattr (view , member_name ))
97+ f .write (getattr (item , member_name ))
8398 print ("saved to " + filename )
8499
85100
0 commit comments