Hi everbody,
I want to export from gis.user.search() the json array "groups".
Here some Information about the "groups": arcgis.gis module — arcgis 1.6.1 documentation
How can I see the groups from user?
Thanks .
from arcgis.gis import GIS
import arcgis
import json
gis = GIS("url_to_portal", "admin_user", "password")
user_accounts = gis.users.search()
group = gis.groups.search()
for user in (str(user_accounts.groups)):
liste = {}
user = json.loads(user_accounts.groups)
print (user)
else:
print("isn't working so far")
#Error Msg
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-18-57b3d16d2703> in <module>
19
---> 20 for user in (str(user_accounts.groups)):
21 liste = {}
AttributeError: 'list' object has no attribute 'groups'
Solved! Go to Solution.
Here's an implementation, code is commented. I have an issue with accessing some users' groups.
from arcgis import GIS
import csv
## connect to agol/portal
agol = GIS("home")
## csv filepath for file creation/overwrite
csv_filepath = r"path\to\user_groups.csv"
## get a list of user objects
users = agol.users.search(max_users=1000)
## create/overwite csv
with open(csv_filepath, 'w', newline="") as csv_file:
writer = csv.writer(csv_file)
## write the header
writer.writerow(["username", "email", "groups"])
## iterate through users
for user in users:
print(user)
## write a new row with info per user
try:
groups = ",".join([group.title for group in user.groups])
new_row = [user.username, user.email, groups]
writer.writerow(new_row)
## i have instances where I cant seem to access a users groups
## you may or may not encounter this issue
except:
new_row = [user.username, "", ""]
writer.writerow(new_row)
print("\t FAILED")
## save the file
csv_file.close()
Hi Shukwaun Cheung,
You might have a look at a Python script which I have published here:
Does this serve your purposes?
Cheers,
Egge-Jan
Hi Egge-Jan Pollé,
thank you for your help.
I was able to create a CSV with help of your script, in which I could see the users with all available groups. Each user had a zero as a result for each group, which means that this user is not in this group. Later I invited a user to a group, I got a one in the whole table as result. I know that there should be serveral ones. 😕
My aim was to list each user's groups in a column with a comma as seperater.
What I got:
What I want:
some Ideas?
Were you ever able to figure this one out?
Here's an implementation, code is commented. I have an issue with accessing some users' groups.
from arcgis import GIS
import csv
## connect to agol/portal
agol = GIS("home")
## csv filepath for file creation/overwrite
csv_filepath = r"path\to\user_groups.csv"
## get a list of user objects
users = agol.users.search(max_users=1000)
## create/overwite csv
with open(csv_filepath, 'w', newline="") as csv_file:
writer = csv.writer(csv_file)
## write the header
writer.writerow(["username", "email", "groups"])
## iterate through users
for user in users:
print(user)
## write a new row with info per user
try:
groups = ",".join([group.title for group in user.groups])
new_row = [user.username, user.email, groups]
writer.writerow(new_row)
## i have instances where I cant seem to access a users groups
## you may or may not encounter this issue
except:
new_row = [user.username, "", ""]
writer.writerow(new_row)
print("\t FAILED")
## save the file
csv_file.close()
Thank you, this was incredibly helpful!