HOW TO
There are situations when items pile up in the root folders of users in the ArcGIS Enterprise portal. When dealing with multiple items, it is often necessary to have the items organized so they can be identified according to their usage. This article describes how to order items in the root folder by their last modified date and move them to a folder ordered by months using ArcGIS API for Python.
from arcgis.gis import GIS,ContentManager import datetime
ago_gis=GIS('https://domain.esri.com/portal','Username','Password', verify_cert=False)
Note: The verify_cert parameter is an optional boolean value. The default value is True if the parameter is not specified. If a site has an invalid SSL certificate or is accessed via the IP or hostname instead of the name on the certificate, set this value to False.
me = ago_gis.users.me
rootitems=me.items(folder=None,max_items=1000)
year=['01-January',
'02-February',
'03-March',
'04-April',
'05-May',
'06-June',
'07-July',
'08-August',
'09-September',
'10-October',
'11-November',
'12-December']
year1=['01-January',
'02-February',
'03-March',
'04-April',
'05-May',
'06-June',
'07-July',
'08-August',
'09-September',
'10-October',
'11-November',
'12-December']
for month in year1:
ago_gis.content.create_folder(month)
DatemodifiedList=[]
for i in rootitems:
d=(i.modified/1000)
dt = datetime.datetime.fromtimestamp(d)
tempstring=str(dt.date())+'-'+i.title
DatemodifiedList.append(tempstring)
for item in rootitems:
epochtime=(item.modified/1000)
date_time = datetime.datetime.fromtimestamp(epochtime)
itemYear=date_time.year
Month=date_time.month
item.move(year[Month-1])
DatemodifiedList
print ("Items are organized")
The following is a sample of the full script:
from arcgis.gis import GIS,ContentManager
import datetime
ago_gis=GIS('https://domain.esri.com/portal','User1','user123', verify_cert=False)
me = ago_gis.users.me
rootitems=me.items(folder=None,max_items=1000)
year=['01-January',
'02-February',
'03-March',
'04-April',
'05-May',
'06-June',
'07-July',
'08-August',
'09-September',
'10-October',
'11-November',
'12-December']
year1=['01-January',
'02-February',
'03-March',
'04-April',
'05-May',
'06-June',
'07-July',
'08-August',
'09-September',
'10-October',
'11-November',
'12-December']
for month in year1:
ago_gis.content.create_folder(month)
DatemodifiedList=[]
for i in rootitems:
d=(i.modified/1000)
dt = datetime.datetime.fromtimestamp(d)
tempstring=str(dt.date())+'-'+i.title
DatemodifiedList.append(tempstring)
for item in rootitems:
epochtime=(item.modified/1000)
date_time = datetime.datetime.fromtimestamp(epochtime)
itemYear=date_time.year
Month=date_time.month
item.move(year[Month-1])
DatemodifiedList
print ("Items are organized")
Article ID: 000029281
Get help from ArcGIS experts
Start chatting now