@@ -25,8 +25,11 @@ def main():
2525 help = "desired logging level (set to error by default)" ,
2626 )
2727 # Options specific to this sample
28- parser .add_argument ("--delete" )
29- parser .add_argument ("--create" )
28+ parser .add_argument ("--create" , action = "store_true" )
29+ parser .add_argument ("--delete" , action = "store_true" )
30+ parser .add_argument ("--refresh" , action = "store_true" )
31+ parser .add_argument ("--workbook" , required = False )
32+ parser .add_argument ("--datasource" , required = False )
3033 args = parser .parse_args ()
3134
3235 # Set logging level based on user input, or error by default
@@ -39,19 +42,45 @@ def main():
3942 server .add_http_options ({"verify" : False })
4043 server .use_server_version ()
4144 with server .auth .sign_in (tableau_auth ):
42- # Gets all workbook items
43- all_workbooks , pagination_item = server .workbooks .get ()
44- print (f"\n There are { pagination_item .total_available } workbooks on site: " )
45- print ([workbook .name for workbook in all_workbooks ])
4645
47- if all_workbooks :
48- # Pick one workbook from the list
49- wb = all_workbooks [3 ]
46+ wb = None
47+ ds = None
48+ if args .workbook :
49+ wb = server .workbooks .get_by_id (args .workbook )
50+ if wb is None :
51+ raise ValueError (f"Workbook not found for id { args .workbook } " )
52+ elif args .datasource :
53+ ds = server .datasources .get_by_id (args .datasource )
54+ if ds is None :
55+ raise ValueError (f"Datasource not found for id { args .datasource } " )
56+ else :
57+ # Gets all workbook items
58+ all_workbooks , pagination_item = server .workbooks .get ()
59+ print (f"\n There are { pagination_item .total_available } workbooks on site: " )
60+ print ([workbook .name for workbook in all_workbooks ])
61+
62+ if all_workbooks :
63+ # Pick one workbook from the list
64+ wb = all_workbooks [3 ]
5065
5166 if args .create :
5267 print ("create extract on wb " , wb .name )
5368 extract_job = server .workbooks .create_extract (wb , includeAll = True )
5469 print (extract_job )
70+
71+ if args .refresh :
72+ extract_job = None
73+ if ds is not None :
74+ print (f"refresh extract on datasource { ds .name } " )
75+ extract_job = server .datasources .refresh (ds , includeAll = True , incremental = True )
76+ elif wb is not None :
77+ print (f"refresh extract on workbook { wb .name } " )
78+ extract_job = server .workbooks .refresh (wb )
79+ else :
80+ print ("no content item selected to refresh" )
81+
82+ print (extract_job )
83+
5584
5685 if args .delete :
5786 print ("delete extract on wb " , wb .name )
0 commit comments