List all distributed collaborations in AGOL

243
3
12-03-2023 08:21 PM
KikSiops
New Contributor III

Hi,

I am an admin to our AGOL and I am trying to create a report including list of all collaboration we have in our AGOL.  This is not included in the built in Report feature in AGOL.

I am using notebook (script provided to me before) in Pro to generate my other reports both for AGOL and enterprise (list of groups, users. etc.) but I don't have a script to generate list of all our distributed collaboration. 

Can someone help me on this please? 

*****************************************

import pandas as pd
from arcgis.gis import GIS
gis = GIS("pro")

import time
# convert Unix epoch time to local time

def format_creation_time(obj):
create_time_raw = time.localtime(obj.created/1000)
create_time_formatted = "{}/{}/{}".format(create_time_raw[0], create_time_raw[1], create_time_raw[2])
return create_time_formatted

def format_lastlogin_time(obj):
lastlog_time_raw = time.localtime(obj.lastLogin/1000)
lastlog_time_formatted = "{}/{}/{}".format(lastlog_time_raw[0], lastlog_time_raw[1], lastlog_time_raw[2])
return lastlog_time_formatted

def format_lastmodified_time(obj):
lastmod_time_raw = time.localtime(obj.modified/1000)
lastmod_time_formatted = "{}/{}/{}".format(lastmod_time_raw[0], lastmod_time_raw[1], lastmod_time_raw[2])
return lastmod_time_formatted

***************************************************

Thanks in advanced!

0 Kudos
3 Replies
rwrenner_esri
Esri Contributor

Does this work for you? Adapted from this documentation:

for collab in gis.admin.collaborations.list():
    print(collab.name)

 

0 Kudos
KikSiops
New Contributor III

Thanks @rwrenner_esri . That works. I also needed additional details so I added these:

for collab in gis.admin.collaborations.list():


print(f" Name: {collab.name}"),
print(f" Description: {collab.description}"),
print(f" Created: {collab.created}"),
print(f" Last Modified: {collab.modified}\n")

- I have an output but don't know how to export it to csv, can you assist me please?  🙂

0 Kudos
rwrenner_esri
Esri Contributor

Glad that works! Below is code which incorporates the addition details into a dataframe then exports it to csv from within ArcGIS Pro.

Just be sure to change the csv export file path on the final line.

-Rylee

#imports, authentication
import pandas as pd
from arcgis.gis import GIS
gis = GIS("pro")

#create empty list 
collab_details = []

#loop through collaboration to add each to list
for collab in gis.admin.collaborations.list():
    collab_details.append("{},{},{},{}".format(collab.name, collab.description, collab.created, collab.modified))

#add all details to single column, comma separated
df = pd.DataFrame(collab_details, columns = ["to_split"]) 
df

#split column into multiple columns & rename
df[['Name', 'Description', 'Type', 'Modified']] = df['to_split'].str.split(',', expand=True)

#export to csv file in specified folder - replace with your url
df.to_csv("C:/Users/..../Documents/ArcGIS/Projects/CollaborationList.csv", columns=['Name', 'Description', 'Type', 'Modified'])
0 Kudos