8000 Refactor the refresh sample to be more explicit (#288) · tableau/server-client-python@d28d5fc · GitHub
[go: up one dir, main page]

Skip to content

Commit d28d5fc

Browse files
author
Russell Hay
authored
Refactor the refresh sample to be more explicit (#288)
1 parent 844e0b1 commit d28d5fc

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

samples/refresh.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main():
1616
parser.add_argument('--server', '-s', required=True, help='server address')
1717
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
1818
parser.add_argument('--site', '-S', default=None)
19-
parser.add_argument('-p', default=None)
19+
parser.add_argument('--password', '-p', default=None, help='if not specified, you will be prompted')
2020

2121
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
2222
help='desired logging level (set to error by default)')
@@ -26,10 +26,10 @@ def main():
2626

2727
args = parser.parse_args()
2828

29-
if args.p is None:
29+
if args.password is None:
3030
password = getpass.getpass("Password: ")
3131
else:
32-
password = args.p
32+
password = args.password
3333

3434
# Set logging level based on user input, or error by default
3535
logging_level = getattr(logging, args.logging_level.upper())
@@ -39,15 +39,21 @@ def main():
3939
tableau_auth = TSC.TableauAuth(args.username, password, args.site)
4040
server = TSC.Server(args.server, use_server_version=True)
4141
with server.auth.sign_in(tableau_auth):
42-
endpoint = {
43-
'workbook': server.workbooks,
44-
'datasource': server.datasources
45-
}.get(args.resource_type)
42+
if args.resource_type == "workbook":
43+
# Get the workbook by its Id to make sure it exists
44+
resource = server.workbooks.get_by_id(args.resource_id)
4645

47-
refresh_func = endpoint.refresh
48-
resource = endpoint.get_by_id(args.resource_id)
46+
# trigger the refresh, you'll get a job id back which can be used to poll for when the refresh is done
47+
results = server.workbooks.refresh(resource)
48+
else:
49+
# Get the datasource by its Id to make sure it exists
50+
resource = server.datasources.get_by_id(args.resource_id)
4951

50-
print(refresh_func(resource))
52+
# trigger the refresh, you'll get a job id back which can be used to poll for when the refresh is done
53+
results = server.datasources.refresh(resource)
54+
55+
print(results)
56+
# TODO: Add a flag that will poll and wait for the returned job to be done
5157

5258

5359
if __name__ == '__main__':

0 commit comments

Comments
 (0)
0