HOW TO
There are several times when items pile up in the root folder of a user in ArcGIS Online. When dealing with multiple items, it is often desirable to have the items to be organized to identify the usage of the items in their respective months.
This article describes how to organize items in the ArcGIS Online Content page root folder by analyzing the last date modified and move it to a folder for the respective month the items were last modified using ArcGIS API for Python. The script can be run using a standalone .py file or through ArcGIS Notebook.
from arcgis.gis import GIS,ContentManager import datetime
ago_gis=GIS('https://arcgis.com','Username','Password')
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 a full script:
from arcgis.gis import GIS,ContentManager import datetime ago_gis=GIS('https://arcgis.com','User1_esri','useresri') 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])#The minus one is to indicate the position in the list DatemodifiedList print ("Items are organized")
Get help from ArcGIS experts
Download the Esri Support App