<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Converting an ArcGIS API Content Search output into a dictionary. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/converting-an-arcgis-api-content-search-output/m-p/1401660#M70197</link>
    <description>&lt;P&gt;This is what I use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#note: this must be run in Python 3.x
#This script will list all ArcGIS Online content, what it is, who owns it, the dates it was created &amp;amp; modified

import arcgis, time
import csv

gis=GIS(url,username,password)


print ("Organization Name: "+str(gis.properties.name))
print ("Portal Name: "+str(gis.properties.portalName))
#print ("URL: "+str(gis.properties.customBaseUrl))
print ("ArcGIS Online Credits Available: "+str("{:,}".format(gis.properties.availableCredits)))
print("ELA Expiration Date: "+str(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(gis.properties.subscriptionInfo.expDate/1000.0))))
print("Max Users per Level: ")
for key,val in gis.properties.subscriptionInfo.maxUsersPerLevel.items():
	    print (key, "=", val)
print ("\n")

#set item_type if you only want to search for ex. "Feature Layer" 
search_result = gis.content.search(query="", item_type="",max_items=10000) #max number is set so it will return more than the default 10 results

outCSVfile=r"L:\Scripts\ArcGISOnline\ArcGISOnline_ContentDetails.csv"
csvfile = open(outCSVfile, 'w',newline='')
writer = csv.writer(csvfile)
writer.writerow(["Title","ItemType","Sharing","Description","Snippet","Tags","Categories","AccessInformation","Protected","Status","OwnedBy","DateCreated","DateLastModified","View Count","Item_ID"])

print("There are: "+str(len(search_result))+" total items in our ArcGIS Online.")

recordNumber = 0
for i in search_result:
    recordNumber+=1
    try:
        description = str(i.description.encode('unicode-escape').decode('utf-8')) #removes emojis
    except:
        description = str(i.description)
 
    #print(i.title+","+","+i.type+","+i.access+","+description+str(i.snippet)+","+str(i.tags)+","+str(i.categories)+","+str(i.accessInformation)+","+str(i.protected)+","+str(i.content_status)+i.owner+","+","+str(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(i.created/1000.0))+","+str(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(i.modified/1000.0))))+","+str(i.numViews)+","+(i.id))
    #print (recordNumber) # so we know the script is doing something
    writer.writerow([i.title, i.type,i.access,description,str(i.snippet),str(i.tags),str(i.categories),str(i.accessInformation),str(i.protected),str(i.content_status),str(i.owner),str(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(i.created/1000.0))),str(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(i.modified/1000.0))),i.numViews,i.id])

csvfile.close()
&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 27 Mar 2024 19:55:26 GMT</pubDate>
    <dc:creator>Tom_Laue</dc:creator>
    <dc:date>2024-03-27T19:55:26Z</dc:date>
    <item>
      <title>Converting an ArcGIS API Content Search output into a dictionary.</title>
      <link>https://community.esri.com/t5/python-questions/converting-an-arcgis-api-content-search-output/m-p/1401398#M70190</link>
      <description>&lt;P&gt;Hello, I am having difficulty auditing organisational content, and I wish to gather a full list of content, the type of content and which user owns this content.&lt;/P&gt;&lt;P&gt;I have accessed the list quite easily using the ArcGIS API -&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/guide/accessing-and-creating-content/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/python/guide/accessing-and-creating-content/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;What I am having difficulty in doing is finding a way to convert the API output into a dictionary in python, to then output into a CSV.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The output type is coming out as&amp;nbsp;&amp;lt;class 'arcgis.gis.Item'&amp;gt;, with an example below:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;[&amp;lt;Item title:"0ff721b591bb4526a0877b4708488db1" type:Feature Layer Collection owner:arcgis_python&amp;gt;,
 &amp;lt;Item title:"UnemploymentRateHotspots245326" type:Feature Layer Collection owner:arcgis_python&amp;gt;,
 &amp;lt;Item title:"6f0e42f4e35540b180f92263da913dba" type:Table Layer owner:arcgis_python&amp;gt;,
 &amp;lt;Item title:"6cf4c07182ef44c3b8d0f64f28a8fd7e" type:Feature Layer Collection owner:arcgis_python&amp;gt;,&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Any assistance would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 13:07:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/converting-an-arcgis-api-content-search-output/m-p/1401398#M70190</guid>
      <dc:creator>SouthCoastGIS</dc:creator>
      <dc:date>2024-03-27T13:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: Converting an ArcGIS API Content Search output into a dictionary.</title>
      <link>https://community.esri.com/t5/python-questions/converting-an-arcgis-api-content-search-output/m-p/1401660#M70197</link>
      <description>&lt;P&gt;This is what I use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#note: this must be run in Python 3.x
#This script will list all ArcGIS Online content, what it is, who owns it, the dates it was created &amp;amp; modified

import arcgis, time
import csv

gis=GIS(url,username,password)


print ("Organization Name: "+str(gis.properties.name))
print ("Portal Name: "+str(gis.properties.portalName))
#print ("URL: "+str(gis.properties.customBaseUrl))
print ("ArcGIS Online Credits Available: "+str("{:,}".format(gis.properties.availableCredits)))
print("ELA Expiration Date: "+str(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(gis.properties.subscriptionInfo.expDate/1000.0))))
print("Max Users per Level: ")
for key,val in gis.properties.subscriptionInfo.maxUsersPerLevel.items():
	    print (key, "=", val)
print ("\n")

#set item_type if you only want to search for ex. "Feature Layer" 
search_result = gis.content.search(query="", item_type="",max_items=10000) #max number is set so it will return more than the default 10 results

outCSVfile=r"L:\Scripts\ArcGISOnline\ArcGISOnline_ContentDetails.csv"
csvfile = open(outCSVfile, 'w',newline='')
writer = csv.writer(csvfile)
writer.writerow(["Title","ItemType","Sharing","Description","Snippet","Tags","Categories","AccessInformation","Protected","Status","OwnedBy","DateCreated","DateLastModified","View Count","Item_ID"])

print("There are: "+str(len(search_result))+" total items in our ArcGIS Online.")

recordNumber = 0
for i in search_result:
    recordNumber+=1
    try:
        description = str(i.description.encode('unicode-escape').decode('utf-8')) #removes emojis
    except:
        description = str(i.description)
 
    #print(i.title+","+","+i.type+","+i.access+","+description+str(i.snippet)+","+str(i.tags)+","+str(i.categories)+","+str(i.accessInformation)+","+str(i.protected)+","+str(i.content_status)+i.owner+","+","+str(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(i.created/1000.0))+","+str(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(i.modified/1000.0))))+","+str(i.numViews)+","+(i.id))
    #print (recordNumber) # so we know the script is doing something
    writer.writerow([i.title, i.type,i.access,description,str(i.snippet),str(i.tags),str(i.categories),str(i.accessInformation),str(i.protected),str(i.content_status),str(i.owner),str(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(i.created/1000.0))),str(time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(i.modified/1000.0))),i.numViews,i.id])

csvfile.close()
&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 27 Mar 2024 19:55:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/converting-an-arcgis-api-content-search-output/m-p/1401660#M70197</guid>
      <dc:creator>Tom_Laue</dc:creator>
      <dc:date>2024-03-27T19:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: Converting an ArcGIS API Content Search output into a dictionary.</title>
      <link>https://community.esri.com/t5/python-questions/converting-an-arcgis-api-content-search-output/m-p/1401685#M70198</link>
      <description>&lt;P&gt;Incredible! Thank you so much for sharing this. Seems so simple now, though my understanding of Python is currently very basic.&lt;/P&gt;&lt;P&gt;This is why I am very glad to use ESRI, since we have access to such an amazing community.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 20:33:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/converting-an-arcgis-api-content-search-output/m-p/1401685#M70198</guid>
      <dc:creator>SouthCoastGIS</dc:creator>
      <dc:date>2024-03-27T20:33:26Z</dc:date>
    </item>
  </channel>
</rss>

