Error trying to overwrite CSV file in add item properties

307
9
Jump to solution
09-23-2022 08:38 AM
zstanley_marin
New Contributor II

I'm trying to overwrite an existing CSV at 15 minute intervals w/ a notebook in AGOL. In the add() method I have the key:value Argument item_properties option set to True for overwrite.

 I, however continuously get an error telling me the file already exists:

 

 

# add the item to AGOL as csv
projectIdeasTable = gis.content.add(item_properties = {"type": "CSV",
                                   "title": "Project Ideas Table",
                                   "summary": "Table of public project ideas for download as part of particpatory budgeting process",
                                   "snippet": "Intended use for users who have trouble reading content in maps or other forms",
                                   "tags": "participatory budgeting",
                                   "access": "public",
                                   "overwrite": True,          
                                    }, data = 'ProjectIdeas.csv')

 

 

Exception: Item 'ProjectIdeas.csv' already exists.
(Error Code: 409)

This seems like a simple issues that shouldn't throw this error. Thoughts? 

0 Kudos
2 Solutions

Accepted Solutions
jcarlson
MVP Honored Contributor

Would it be better to use the arcgis.gis.Item.update() instead? That should specifically allow you to update the content of the given item in-place, rather than attempt to add a "new" item.

- Josh Carlson
Kendall County GIS

View solution in original post

zstanley_marin
New Contributor II

The problem is I have to collect data from a feature layer that is turned on for public data collection. The CSV needs to be overwritten with data from the updated feature layer. The CSV will ultimately be shared publicly for downloaded for people with disabilities.

View solution in original post

0 Kudos
9 Replies
jcarlson
MVP Honored Contributor

Would it be better to use the arcgis.gis.Item.update() instead? That should specifically allow you to update the content of the given item in-place, rather than attempt to add a "new" item.

- Josh Carlson
Kendall County GIS
zstanley_marin
New Contributor II

The problem is I have to collect data from a feature layer that is turned on for public data collection. The CSV needs to be overwritten with data from the updated feature layer. The CSV will ultimately be shared publicly for downloaded for people with disabilities.

0 Kudos
John_Spence
Occasional Contributor III

Oh!!!! Don't do it this way. Go through Hub. If you share the feature layer as a view w/ hub and turn on the export options, the CSV is automatically handled.

https://data.bellevuewa.gov as an example only has services published daily and the CSV, Shapefiles, etc are all auto generated on demand.

zstanley_marin
New Contributor II

I will explore this solution - thanks!

John_Spence
Occasional Contributor III

Reach out if you run into any issues. We would be happy to give some pointers we learned along the way.

zstanley_marin
New Contributor II

Thanks! The real challenge we run into with this approach is disabled folks ability to get to the location to actually download the data. We have a hub site with an embedded web app and will link directly to the CSV below this app.

0 Kudos
John_Spence
Occasional Contributor III

What we did to overcome this, was to put a link to the dataset (https://data.bellevuewa.gov/datasets/cobgis::regional-power-outages-current/explore?layer=0&location...) and the download button is prominently displayed along with the information about the dataset. Our HR folks have people with disabilities on staff so we were able to test a wide variety of conditions to see if that would work. The biggest issue we all have though with the Esri online products, especially embedding (iframes) is that sometimes the screen readers do not exactly work well.

zstanley_marin
New Contributor II

Yeah, we have to test everything on screen readers to meet our accessibility standards. Thanks for all the help.

John_Spence
Occasional Contributor III
        # Find Item
        search_result= connectedP.content.search(serviceID, 'Feature Layer')
        FS_item = search_result[0]

        targetedOverwrite = FeatureLayerCollection.fromitem(FS_item)

        time.sleep(90)

        fileTransfer = r'{}\{}'.format(path_Proj, fileName)
        print ('Updating {} using {}'.format(FS_item.title, fileName))

        # Send for update
        try:
            targetedOverwrite.manager.overwrite(fileTransfer)
            print ('\tSuccessful update of {} \r\r'.format(FS_item.title))

 

Frankly though, I would not do it this way (recommend) and would likely look at directly accessing the data source or scraping the CSV to a database where you add/remove/update records and then publish/update the service either via writing to the service (depending on record account that might be the most efficient way) or by overwriting the service.

 

        # Share to portal
        print('     ...Uploading Service Definition')
        arcpy.UploadServiceDefinition_server(inSdFile, inServer, inServiceName, inCluster, inFolderType, inFolder,
                                             inStartup, inOverride, inMyContents, inPublic, inOrganization, inGroups)
0 Kudos