This python in an AGOL Jupyter notebook returns me a list of usernames in the group as demo'd here: arcgis.gis module — arcgis 1.8.0 documentation .
Is there a smart way to return the users profile name, rather than their username.
sa_groups = org_gis.groups.search('title:SA')
g = sa_groups[2]
response = g.get_members()
for user in response['users'] :
print(user)
Solved! Go to Solution.
Peter,
It looks like the get_members() function returns a dictionary that contains three lists: users, admins, and owners. The contents of these lists are strings, so it doesn't look like we can derive the full name of each user as-is. However, using list comprehensions, you can create a list of <User> objects whose username appears in the resulting dictionary from get_members(). From this new list, you can print each user's name using the fullName property. See the code below:
# Get a list of groups that have "SA" in the title. sa_groups = org_gis.groups.search('title:SA') # Get a list of all users in the portal (max 1000 users). all_users = org_gis.users.search(max_users=1000) # Select the third group in the list g = sa_groups[2] # Get a dictionary of all users, admins, owners of the group. response = g.get_members() # Create a list of user objects whose usernames appear in the "users" list of the "response" dictionary. lst = [u for u in all_users if u.username in response["users"]]
# Authentication portalURL = "" username = "" password = "" org_gis = GIS(portalURL, username, password)
# Print the full name of each user in the list. for user in lst: print(user.fullName)
Peter,
It looks like the get_members() function returns a dictionary that contains three lists: users, admins, and owners. The contents of these lists are strings, so it doesn't look like we can derive the full name of each user as-is. However, using list comprehensions, you can create a list of <User> objects whose username appears in the resulting dictionary from get_members(). From this new list, you can print each user's name using the fullName property. See the code below:
# Get a list of groups that have "SA" in the title. sa_groups = org_gis.groups.search('title:SA') # Get a list of all users in the portal (max 1000 users). all_users = org_gis.users.search(max_users=1000) # Select the third group in the list g = sa_groups[2] # Get a dictionary of all users, admins, owners of the group. response = g.get_members() # Create a list of user objects whose usernames appear in the "users" list of the "response" dictionary. lst = [u for u in all_users if u.username in response["users"]]
# Authentication portalURL = "" username = "" password = "" org_gis = GIS(portalURL, username, password)
# Print the full name of each user in the list. for user in lst: print(user.fullName)
of course! thanks Joshua Herman
additionally (and probably obvious to python pro's) , to return these in an email recipient list, you can modify from
print(user.fullName)
to
to print(str(user.email) + ",")