from arcgis.gis import GIS
import datetime
# login to your gis
gis = GIS("yourlink", "username", "password", proxy_host = "if you using one", proxy_port = 8080)
search_result = gis.content.search(query = '*', item_type="Feature Service",max_items=10000)
# list to record items
list_of_items = list()
# as I am adding all in a table after, I need headings
list_of_items.append(['title', 'id', 'views', 'created', 'owner', 'size', 'access', 'url', 'source url'])
for i in search_result:
# using try as sometimes it goes upset and won't work...
try:
# not all items have sourceUrl. For exmaple, hosted items don't have it.
if hasattr(i, 'sourceUrl'):
source = i.sourceUrl
unix_date =i.created # unix ms second date/time
normal_date = datetime.datetime.fromtimestamp(unix_date / 1e3)
# adding properties of one item as a list
list_of_items.append([i.title, i.itemid, i.numViews, normal_date, i.owner, i.size, i.access, i.url, i.sourceUrl])
except:
continue