I am building a Python script for a client who wants a bunch of hosted feature services exported to file geodatabases. The script I've written works just fine. Each hosted feature service is exported to a GDB then downloaded to a location of my choosing.

The issue is that each unzipped GDB has a seemingly random name. For example:

'Test_Layer_1.zip' once unzipped turns into '_ags_dataD621677BB64F4D2D98CD0D1B1CF805BD.gdb'.

Is there a way to set the name of the GDB as a parameter when you pull it down?

Here is what I've worked out so far...

# Import modules
import os
import datetime
from arcgis.gis import GIS

# Create destination folder 
today = datetime.datetime.now()
path = 'C:/workspace/pythontest' + today.strftime('%m%d%Y')
dest = path
extension = ".zip"

# Define variables for GIS
PortalUrl = 'https://redacted.redacted.local/portal'
PortalUserName = 'username'
PortalPassword = 'password'
gis = GIS(PortalUrl, PortalUserName, PortalPassword)

# Define input layers
# itemid1 = 'c9325f2f3d7b430b93047230bbe004ac' = 'Test_Layer_1'
# itemid2 = 'edfe40f03dee40839a92ee2bd695cf62' = 'Test_Layer_2'
itemid1 = 'c9325f2f3d7b430b93047230bbe004ac'
itemid2 = 'edfe40f03dee40839a92ee2bd695cf62'

# Export Test_Layer_1
dataitem1 = gis.content.get(itemid1)
dataitem1.export('Test_Layer_1', 'File Geodatabase', parameters=None, wait=True)
myexport1 = gis.content.search('Test_Layer_1', item_type='File Geodatabase')
fgdb1 = gis.content.get(myexport1[0].itemid)
fgdb1.download(save_path=dest, file_name='Test_Layer_1' + ".zip")

# Export Test_Layer_2
dataitem2 = gis.content.get(itemid2)
dataitem2.export('Test_Layer_2', 'File Geodatabase', parameters=None, wait=True)
myexport2 = gis.content.search('Test_Layer_2', item_type='File Geodatabase')
fgdb2 = gis.content.get(myexport2[0].itemid)
fgdb2.download(save_path=dest, file_name='Test_Layer_2' + ".zip")


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.