Hello
I've got code below which works well to export list of groups and members, but I want to also include the group owners and managers in the export (not just members).
How do I tweak this? Thanks in advance.
from arcgis.gis import GIS
from datetime import datetime
import pandas as pd #import pandas module
gis = GIS("pro") #login using Pro authentication
# groups
grps = gis.groups.search(max_groups=10000)
grp_list = []
for g in grps:
for u in g.get_members()['users']:
grp_list.append({'group':g.title, 'user':u})
g_df = pd.DataFrame(grp_list)
#users
users = gis.users.search(max_users=10000)
user_list = []
for u in users:
user_list.append({'user':u.username, 'role':u.role, 'email':u.email})
u_df = pd.DataFrame(user_list)
#set path to output file
outputFile = r"C:\Data\Temp\Groups_Members_"+datetime.now().strftime("%Y-%m-%d")+".CSV" # change if required
# output merged doc
g_df.merge(u_df, on='user', how='left').to_csv(outputFile)
print("finished")
Use the group object user_list() method instead to return this information. Documentation here.
The method returns a dictionary that contains two key: owner and users.
The value for the owner is a a dictionary.
The value for the users is a list of dictionaries containing information about each other member that is not the owner. Each dictionary has a memberType key with a value of admin for a group manager or member for all other members.
Hope that helps.