Why does item status return "Item status doesn't exist?"

765
2
11-16-2018 09:43 AM
deleted-user-Qrnw90viByMg
New Contributor III

I want to download a series of file geodatabases from ArcGIS Online after they've successfully exported from their respective feature classes.  I want to start all of the exports at the same time, let them all run simultaneously, then download them.  

In order to do that, I've put together the following script. The problem is, though, I can't get a status on some of the geodatabases. 

Here's the script: 

### BEGIN SCRIPT ###
from arcgis.gis import GIS,Item,User 
from datetime import datetime as dt 
import os,smtplib  

#Define Function to Send Email 
def sendError(message):
     print("\tSending results in email.")
     fromaddr = 'you@gmail.com'
     toaddrs = 'me@gmail.com'
     username = 'user@gmail.com'
     password = '1234abcd'
     server = smtplib.SMTP('smtp.gmail.com:587')
     server.starttls()
     server.login(username,password)
     server.sendmail(fromaddr,toaddrs,message)
     print ("\tMail Sent!")
     server.quit()
  try:
     
     #Set login information for AGO
     username = "user_name"
     password = "pass_word"
     #Set GIS environment
     gis=GIS(url="https://city.maps.arcgis.com",username=username,password=password)

     #Assign User as 'user_name' to gain work with citizen reporter's content
     user = User(gis,'user_name',None)
     #Set datestamp variable
     datestamp = dt.now().strftime("%Y%m%d")

     #Assign path for backup folder; create it if it doesn't exist
     backup_folder = 'AGO_backup_' + datestamp
     backup_folder_path = os.path.join(r'AGO_backups',backup_folder)
     if not os.path.exists(backup_folder_path):
         os.makedirs(backup_folder_path)
      #Assemble list of folders for citizen_reporter user
     folder_list = user.folders
     #Create list for database items
     db_list = []
     itemID_list = []
     counter = 0
     #Go to 'Report Layers' folder, then export and download all items
     for folder in folder_list:
         if folder['title'] == 'Feature Layers':
             item_list = user.items(folder)
             for item in item_list:
                 item_name = str(item['title']) + '_' + datestamp
                 if item['type'] == 'Feature Service':
                     db_list.append(item_name)
                     print('exporting %s' % item_name)
                     item.export(item_name,'File Geodatabase', None, True)
                     counter += 1
     #Download the geodatabases that were just exported
     print(db_list)     while len(itemID_list) < counter:
         for db in db_list:
             gdb = gis.content.search(query = db)
             print('%s: %s' % (db,gdb[0].status()['statusMessage']))
             if gdb[0].status()['statusMessage'] == 'completed':
                 if gdb[0].status()['itemId'] not in itemID_list:
                     itemID_list.append(gdb[0].status()['itemId'])
                     print('%s %s added to list' % (db,gdb[0].status()['itemId']))
     for itemID in itemID_list:
         itemObject = gis.content.get(itemID)
         itemObject.download(backup_folder_path)
         itemObject.delete()  except Exception:
     e = sys.exc_info()[1]
     body = "Backup of AGO data failed. \nError: " + str(e)
     message = 'Subject: %s\n\n%s' % ("AGO Backup_FeatureLayers.py failed...", body)
     sendError(message)
### END SCRIPT ###

Here is an example of the messages I get:

Any thoughts or comments on this would be much appreciated. Thanks!

0 Kudos
2 Replies
AdrianWelsh
MVP Honored Contributor

Craig,

Did you find a solution for this?

Could you essentially run an ArcPy task to check if the item exists first?

Exists—ArcPy Functions | ArcGIS Desktop 

0 Kudos
deleted-user-Qrnw90viByMg
New Contributor III

Adrian,

I started working with someone at ESRI and he's been very helpful, but haven't quite come up with a solution yet.

I appreciate the suggestion, but I don't think the Exists function will serve this purpose. I'm specifically interested in retrieving the Status of an item because I need to know when it's finished exporting, not just that it has been created.

0 Kudos