#### # This script demonstrates how to export a view using the Tableau # Server Client. # # To run the script, you must have installed Python 3.7 or later. #### import argparse import logging import tableauserverclient as TSC def main(): parser = argparse.ArgumentParser(description="Export a view as PNG") parser.add_argument("--server", "-s", default="https://prod-useast-a.online.tableau.com") parser.add_argument("--site", "-S", default="roofconnect") parser.add_argument("--token-name", "-p", default="StephenAdminPAT") parser.add_argument("--token-value", "-v", default="rICUXGTWTNSpIiOZ3LS57A==:9UXmB6wQbvpVUIsPlYmt1VnxEv5XI1Tb") parser.add_argument("--resource_id", default="9d8f7b20-9a24-4f8f-af74-39a956827012") parser.add_argument("--file", "-f", default="Weekly Game Export") args = parser.parse_args() logging.basicConfig(level=logging.ERROR) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False}) with server.auth.sign_in(tableau_auth): try: # Get view view = server.views.get_by_id(args.resource_id) if not view: print(f"No view found for id {args.resource_id}") exit(1) print(f"View found: {view.name}") # Create image options image_req_option = TSC.ImageRequestOptions() # Export image server.views.populate_image(view, image_req_option) if view.image is not None: file_path = f"{args.file}.png" with open(file_path, 'wb') as f: f.write(view.image) print(f"Exported to: {file_path}") else: print("Error: No image data received") except Exception as e: print(f"Error: {str(e)}") exit(1) if __name__ == "__main__": main()