I've got https://community.esri.com/thread/219121-find-all-content-for-all-users-in-an-agol-subscription working, but what I'm looking for is some parsed output, hopefully a CSV that shows ITEM NAME, TYPE, OWNER, description,snippet, tags, shared_with, Basically everything from https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.toc.html#item
Hoping this is a pretty common thing and someone has some code snippets they can share.
Solved! Go to Solution.
Here you go:
from arcgis.gis import GIS
import csv
import getpass
portal = input('Enter the URL of the portal instance')
username = input('Enter the username')
password = getpass.getpass()
gis = GIS(portal, username, password)
#leave the type param blank to return all types
itemsList = gis.content.search('', '', max_items = 100)
#list of fields to populate our header in the CSV
fields = ['Title', 'Type', 'Size', 'Owner', 'Description', 'Tags', 'Snippet', 'Categories', 'Access', 'URL', 'Shared With']
def itemRetrieval(arr, csvPath):
try:
with open(csvPath, 'w', encoding='utf-8', newline = '') as outfile:
csvfile = csv.writer(outfile)
csvfile.writerow(arr)
for item in itemsList:
print(item)
row = [item.title, item.type, item.size, item.owner, item.description, item.tags, item.snippet, item.categories, item.access, item.url, item.shared_with]
csvfile.writerow(row)
except Exception as error:
print('The following error occurred: ', error)
itemRetrieval(fields, input('Paste Path and Name of Output File : '))
Here you go:
from arcgis.gis import GIS
import csv
import getpass
portal = input('Enter the URL of the portal instance')
username = input('Enter the username')
password = getpass.getpass()
gis = GIS(portal, username, password)
#leave the type param blank to return all types
itemsList = gis.content.search('', '', max_items = 100)
#list of fields to populate our header in the CSV
fields = ['Title', 'Type', 'Size', 'Owner', 'Description', 'Tags', 'Snippet', 'Categories', 'Access', 'URL', 'Shared With']
def itemRetrieval(arr, csvPath):
try:
with open(csvPath, 'w', encoding='utf-8', newline = '') as outfile:
csvfile = csv.writer(outfile)
csvfile.writerow(arr)
for item in itemsList:
print(item)
row = [item.title, item.type, item.size, item.owner, item.description, item.tags, item.snippet, item.categories, item.access, item.url, item.shared_with]
csvfile.writerow(row)
except Exception as error:
print('The following error occurred: ', error)
itemRetrieval(fields, input('Paste Path and Name of Output File : '))
portal_firsturl = 'url'
portal_firstuser = 'user'
portal_firstpass = 'pwd'
def authenticate_portal(portalurl, portaluser, portalpass):
try:
portal = arcgis.GIS(portalurl, portaluser, portalpass)
if not portal.properties.user.role == 'org_admin':
return False
return portal
except:
raise
def getItemInfo(listsorteditems):
portalrelationshipgroups=dict()
portalrelationshipgroups=[]
for p,item in enumerate(listsorteditems):
grp=[]
for index in range(len(item.shared_with['groups'])):
grp.append(item.shared_with['groups'][index]['title'])
portalrelationshipgroups.append( { "title": item["title"],"id":item.id,"type":item["type"],"owner":item.owner,"shared_with":",".join(grp),"description":item.description,"snippet":item.snippet,"tags":",".join(item.tags)} )
with open('test.csv', 'w') as myfile:
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL,delimiter='\n')
wr.writerow(portalrelationshipgroups)
portalobj = authenticate_portal(portal_firsturl,portal_firstuser,portal_firstpass)
listitems_first = portalobj.content.search('', max_items=10)
listsorteditems_first = sorted(listitems_first, key=lambda k: k['title'])
itemInfo = getRelationshipGroups(listsorteditems_first)