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 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 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()
Example #4
0
def sign_in():
    connection = TableauServerConnection(tableau_server_config)
    connection.sign_in()
    return connection
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
    all_users_data['lastLogin'] = pd.to_datetime(all_users_data['lastLogin'])

    # creating a new column with just now() time, converting to same timezone as lastLogin Column else it will throw TypeError: DatetimeArray subtraction must have the same timezones or no timezones
Example #6
0
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
Example #7
0
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