import requests import sys # Sisense API base URL and authentication token host_url = "" base_url = f"{host_url}/api/v1" base_urlv2 = f"{host_url}/api/v2" api_token = "" # Construct the URL for getting the list of data models url = f"{base_urlv2}/datamodels/schema?fields=title%2Cshares" # Set up the headers with the authentication token headers = { "Authorization": f"Bearer {api_token}", "Content-Type": "application/json", } # Function to get the list of dashboards for a particular user def get_user_dashboards(user_name): # Make the GET request dm = requests.get(url, headers=headers) # Check if the request was successful (status code 200) if dm.status_code == 200: datamodels = dm.json() else: print(f"Error: {dm.status_code} - {dm.text}") # Construct the URL for getting the list of users url2 = f"{base_url}/users?fields=_id%2CuserName%2Cgroups" # Make the GET request userscontent = requests.get(url2, headers=headers) # Check if the request was successful (status code 200) if userscontent.status_code == 200: users = userscontent.json() else: print(f"Error: {userscontent.status_code} - {userscontent.text}") # Loop through users for user in users: if user_name in user["userName"]: user_id = user["_id"] user_groups = user.get("groups", []) user_datamodels = [ datamodel["title"] for datamodel in datamodels if any( user_id == share["partyId"] or share["partyId"] in user_groups for share in datamodel["shares"] ) ] # Output the result print(f"{user['userName']}'s Data models: {', '.join(user_datamodels)}") # Check if a command-line argument is provided if len(sys.argv) > 1: # Get the userName from the command line user_name_argument = sys.argv[1] # Call the function with the provided userName get_user_dashboards(user_name_argument) else: print("Please provide a userName substring as a command-line argument.")