Python/Python tableauserverclient
Python tableauserverclient : Refresh workbook
CosmosProject
2020. 12. 21. 16:28
728x90
반응형
Tableau Server Client(TSC)
Let us check how to refresh workbook.
Filtering workbook using workbook name and refresh that workbook.
# --------------------------------------------------
# Chapter 3. Tableau workbbok refresh
# To refresh workbook you need workbook id of the workbook you want to refresh.
# To get workbook id, you can use filter function in Chapter 2
# --------------------------------------------------
import tableauserverclient as TSC
def TSC_filter_workbook():
tableau_server_url = 'tableau_url' # e.g. https://tableau-server.test.com
tableau_user_id = 'tableau_id'
tableau_user_pw = 'tableau_password'
server = TSC.Server(tableau_server_url)
tableau_auth = TSC.TableauAuth(tableau_user_id, tableau_user_pw)
print('Current REST API Version :', server.version)
server.version = '2.8' # Set version as 2.8
print('Modified Rest API Version :', server.version, '\n')
server.auth.sign_in(tableau_auth)
print('Logged in')
# In this example, I'm going to refresh workbook named 'A Dashboard'
# So I should get the workbook id of 'Quality Dashboard' using filter function.
req_options = TSC.RequestOptions()
req_options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
TSC.RequestOptions.Operator.Equals,
'A Dashboard'))
filter_items, pagination_items = server.workbooks.get(req_options)
workbook_info = filter_items[0]
workbook_name = workbook_info.name
workbook_id = workbook_info.id
print('Target workbook name :', workbook_name)
print('Target workbook id :', workbook_id, '\n')
# 'workbook_id' contains 'A Dashboard' workbooks's id.
# server.workbooks.get_by_id(workbook_id) means that give me 'workbook's information from 'server' with the 'workbook_id'
# And the workbook info will be put in 'workbook' variable.
# 'workbook.get_by_id' method is used when you have workbook id and you want to get the workbook's information.
workbook = server.workbooks.get_by_id(workbook_id)
server.workbooks.refresh(workbook) # 'workbook.refresh' method refreshes extracts of parameter(in this example refresh extracts of workbook in 'workbook' variable)
print('The workbook \'{}\' was refreshed.'.format(workbook_name), '\n')
server.auth.sign_out()
print('Logged out')
# Example Directory Structure
# Team_Apple (-> Project)
# ├── A Dashboard (-> Workbook)
# │ └── A Graph (-> View)
# ├── B Dashboard - PL (-> Workbook)
# │ └── B History (-> View)
# └── C (-> Workbook)
# ├── D_1 C (-> View)
# └── C History (-> View)
- Output
Current REST API Version : 2.3
Modified Rest API Version : 2.8
Logged in
Target workbook name : A Dashboard
Target workbook id : 95ad193f-g2ea-6132-b84d-b573523d0396
The workbook 'A Dashboard' was refreshed.
Logged out
728x90
반응형