def main(): conn = TableauServerConnection(config_json=tableau_server_config) conn.sign_in() users = conn.get_users_on_site().json() print("pandas datetime: ", pd.datetime.now()) print('Fetched users from server {}'.format(conn.server)) print(users) print(conn.server_info().json()) conn.sign_out()
def get_extract_refresh_tasks_for_site( conn: TableauServerConnection) -> List[Dict[str, Any]]: """Returns a list of Python dicts describing all extract refresh tasks for the active site.""" try: return conn.get_extract_refresh_tasks_for_site().json( )["tasks"]["task"] except KeyError: raise ContentNotFound(content_type="extract refresh tasks")
def query_user(**kwargs): user_id = kwargs['user_id'] conn = TableauServerConnection(config_json=tableau_server_config) conn.sign_in() user_data = conn.query_user_on_site(user_id) print(user_data.json()) conn.sign_out()
def get_view_data_dataframe( conn: TableauServerConnection, view_id: str, parameter_dict: Optional[Dict[str, Any]] = None) -> pd.DataFrame: """Returns a DataFrame containing the data downloaded from a Tableau view.""" view_data = conn.query_view_data(view_id=view_id, parameter_dict=parameter_dict) view_df = pd.read_csv(StringIO(view_data.text)) return view_df
def main(): print(pd.datetime.now()) conn = TableauServerConnection(config_json=tableau_server_config) conn.sign_in() print(os.listdir(os.getcwd())) users_json = conn.get_users_on_site().json() print(users_json) conn.sign_out()
def get_workbook_connections_dataframe(conn: TableauServerConnection, workbook_id: str) -> pd.DataFrame: """Returns a DataFrame describing the connections associated with the specified workbook.""" try: connections_json = conn.query_workbook_connections( workbook_id).json()["connections"]["connection"] connections_df = pd.DataFrame(connections_json) connections_df = flatten_dict_column(connections_df, keys=["id", "name"], col_name="datasource") except KeyError: connections_df = pd.DataFrame() return connections_df
def sign_in(): connection = TableauServerConnection(tableau_server_config) connection.sign_in() return connection
os.chdir('/Users/surbhiagrawal/Downloads/Tableau Python Practice') N = int(input('Plesae enter number of days since user has not logged in ? ')) config = { 'tableau_prod': { 'server': 'https://tableau.staging.workpath.com/', 'api_version': '<YOUR_API_VERSION>', 'username': '******', 'password': '******', 'site_name': '<YOUR_SITE_NAME>', 'site_url': '<YOUR_SITE_URL>' } } conn = TableauServerConnection(config, env='tableau_staging') #Logging into Tableau server conn.sign_in() # get a dataframe which has all the sites present, we can access contentUrl from this dataframe to loop over. sites = get_sites_dataframe(conn) print(f'Avaiable sites are {sites}') for i in sites['contentUrl']: conn.switch_site(i) # switching to the site for each site in a list print(f'Current site is {i}') # getting a dataframe of all users in that current site all_users_data = get_users_dataframe(conn) # converting last-login columns to a datetime column as currently it is Object type
config = { 'tableau_prod': { 'server': 'https://<YOUR_SERVER>.com', 'api_version': '<YOUR_API_VERSION>', 'username': '******', 'password': '******', 'site_name': '<YOUR_SITE_NAME>', 'site_url': '<YOUR_SITE_URL>' } } schedule_priority = int( input('Please enter a schedule priority to be chnaged ?')) # establishing a conenction object conn = TableauServerConnection(config, env='tableau_prod') # signing to the server conn.sign_in() # querying all the avaiable schedules schedule_id = conn.query_schedules() # printing the total avaiable schedules accessing the json object print(schedule_id.json()['pagination']['totalAvailable']) # create a loop over the number of times of schedules present for i in range(int(schedule_id.json()['pagination']['totalAvailable'])): # changing the schedule priority if the name of the schedule is equal to a ceratin name if schedule_id.json( )['schedules']['schedule'][i]['name'] == 'Weekday early mornings':
import pandas as pd print(sample_config) config = { 'tableau_prod': { 'server': 'https://<YOUR_SERVER>.com', 'api_version': '<YOUR_API_VERSION>', 'username': '******', 'password': '******', 'site_name': '<YOUR_SITE_NAME>', 'site_url': '<YOUR_SITE_URL>' } } conn = TableauServerConnection(config, env='tableau_prod') # signing in to the Tableau server conn.sign_in() # get all the sites on Server in a dataframe sites_data = get_sites_dataframe(conn) site_choose = input('Under which site do you want to publish the data source ') project_choose = input( 'Under which Project do you want to publish the data source ') x = str(sites_data[sites_data['name'] == site_choose]['contentUrl']) ##print(type(x)) #print(x.split()[1]) # Switching to the site which user entered, and where he want to publish data source
def get_basic_auth_responses(): conn = TableauServerConnection(tableau_server_config) sign_in_response = conn.sign_in() sign_out_response = conn.sign_out() return sign_in_response, sign_out_response
def get_original_content_url(): conn = TableauServerConnection(tableau_server_config) conn.sign_in() original_site = conn.query_site().json() original_content_url = original_site['site']['contentUrl'] return conn, original_content_url
from tableau_api_lib import TableauServerConnection from .config import tableau_server_config from tableau_api_lib.utils import extract_pages from tableau_api_lib.utils import clone_schedules, copy_schedule_state TEST_SCHEDULE_NAMES = ['estam_test extract schedule', 'estam_test hourly end'] TEST_CLONE_NAME_PREFIX = 'estam_auto_' conn = TableauServerConnection(tableau_server_config) def test_sign_in(): conn.sign_in() def test_extract_pages_default(): test_query = conn.query_sites().json() total_sites_available = int(test_query['pagination']['totalAvailable']) extracted_sites = extract_pages(conn.query_sites) print("\nNumber of extracted sites: {}\nNumber of available sites: {}". format(len(extracted_sites), total_sites_available)) assert len(extracted_sites) == total_sites_available def test_extract_pages_limit(): results_limit = 75 test_query = conn.query_sites().json() total_sites_available = int(test_query['pagination']['totalAvailable']) extracted_sites = extract_pages(conn.query_sites, limit=results_limit) print("\nNumber of extracted sites: {}\nNumber of available sites: {}".
def publish_test_workbook(): test_project_id = get_test_project_id(conn) response = conn.publish_workbook( workbook_file_path=TEST_WORKBOOK_FILE_PATH, workbook_name=TEST_WORKBOOK_PREFIX + 'a', project_id=test_project_id, show_tabs_flag=False, parameter_dict={ 'overwrite': 'overwrite=true', 'asJob': 'asJob=true' }) print("Published workbook: {}".format(response.content)) assert response.status_code in [201, 202] conn = TableauServerConnection(tableau_server_config) conn.sign_in() publish_test_workbook() def test_create_schedule(): response = conn.create_schedule(schedule_name=TEST_SCHEDULE_NAME, schedule_type='subscription', start_time='09:00:00') print(response.content) assert response.status_code in [200, 201] def test_create_subscription(): time.sleep(3) print(conn.query_workbooks_for_site().json())
def get_views_for_workbook_dataframe(conn: TableauServerConnection, workbook_id: str) -> pd.DataFrame: """Returns a DataFrame containing details for the views contained within the specified workbook.""" views_for_workbook = conn.query_views_for_workbook(workbook_id=workbook_id) return pd.DataFrame(views_for_workbook.json()["views"]["view"])