|
5 | 5 | # For more information, refer to the documentations on 'Query View Image' |
6 | 6 | # (https://onlinehelp.tableau.com/current/api/rest_api/en-us/help.htm) |
7 | 7 | # |
8 | | -# To run the script, you must have installed Python 3.5 or later. |
| 8 | +# To run the script, you must have installed Python 3.6 or later. |
9 | 9 | #### |
10 | 10 |
|
11 | 11 | import argparse |
12 | | -import getpass |
13 | 12 | import logging |
14 | 13 |
|
15 | 14 | import tableauserverclient as TSC |
|
18 | 17 | def main(): |
19 | 18 |
|
20 | 19 | parser = argparse.ArgumentParser(description='Download image of a specified view.') |
| 20 | + # Common options; please keep those in sync across all samples |
21 | 21 | parser.add_argument('--server', '-s', required=True, help='server address') |
22 | | - parser.add_argument('--site-id', '-si', required=False, |
23 | | - help='content url for site the view is on') |
24 | | - parser.add_argument('--username', '-u', required=True, help='username to sign into server') |
25 | | - parser.add_argument('--view-name', '-v', required=True, |
| 22 | + parser.add_argument('--site', '-S', help='site name') |
| 23 | + parser.add_argument('--token-name', '-p', required=True, |
| 24 | + help='name of the personal access token used to sign into the server') |
| 25 | + parser.add_argument('--token-value', '-v', required=True, |
| 26 | + help='value of the personal access token used to sign into the server') |
| 27 | + parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', |
| 28 | + help='desired logging level (set to error by default)') |
| 29 | + # Options specific to this sample |
| 30 | + parser.add_argument('--view-name', '-vn', required=True, |
26 | 31 | help='name of view to download an image of') |
27 | 32 | parser.add_argument('--filepath', '-f', required=True, help='filepath to save the image returned') |
28 | 33 | parser.add_argument('--maxage', '-m', required=False, help='max age of the image in the cache in minutes.') |
29 | | - parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', |
30 | | - help='desired logging level (set to error by default)') |
31 | 34 |
|
32 | 35 | args = parser.parse_args() |
33 | 36 |
|
34 | | - password = getpass.getpass("Password: ") |
35 | | - |
36 | 37 | # Set logging level based on user input, or error by default |
37 | 38 | logging_level = getattr(logging, args.logging_level.upper()) |
38 | 39 | logging.basicConfig(level=logging_level) |
39 | 40 |
|
40 | 41 | # Step 1: Sign in to server. |
41 | | - site_id = args.site_id |
42 | | - if not site_id: |
43 | | - site_id = "" |
44 | | - tableau_auth = TSC.TableauAuth(args.username, password, site_id=site_id) |
45 | | - server = TSC.Server(args.server) |
46 | | - # The new endpoint was introduced in Version 2.5 |
47 | | - server.version = "2.5" |
48 | | - |
| 42 | + tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) |
| 43 | + server = TSC.Server(args.server, use_server_version=True) |
49 | 44 | with server.auth.sign_in(tableau_auth): |
50 | 45 | # Step 2: Query for the view that we want an image of |
51 | 46 | req_option = TSC.RequestOptions() |
|
0 commit comments