Select to view content in your preferred language

Python Script Using ArcGIS Online Credentials

6166
14
Jump to solution
08-09-2016 06:41 AM
ISP_graynic
Frequent Contributor


I have a basic python script that takes a hosted feature service from ArcGIS Online and converts it to an excel (.xls) file.  The only problem is, I need to sign-in to ArcGIS Online within ArcMap to get the script to run, since the feature service is only shared with my organization.  Is there any way to store my credentials within the script so that it will run on a daily basis without me having to sign-in on ArcMap every time?  Any help is greatly appreciated.  Thank you!

0 Kudos
14 Replies
JakeSkinner
Esri Esteemed Contributor

I would have to take a look at the service to see what's going on.  If you want, you can share the service to a group in AGOL and invite my user account (jskinner_CountySandbox) to it.

0 Kudos
ISP_graynic
Frequent Contributor

Ok, thanks.  I have invited you to a group to check out the service.  When I remove the code below from the script, the script will run and it downloads the attachments and puts them in a folder, but the GlobalID_Str field is empty as well as the entire attachment table created is empty. 

    for key in dict:

        with arcpy.da.UpdateCursor(fc, [OID, "GlobalID_Str"], OID + " = " + str(key)) as cursor:

            for row in cursor:

                row[1] = dict[key]

                cursor.updateRow(row)

0 Kudos
JakeSkinner
Esri Esteemed Contributor

You OBJECTID field in AGOL is OBJECTID_1, but when you download the data it's converted back to OBJECTID. 
You can change the code to fix this.  Open the .py file in a text editor and under line 340 add the following:

OID = "OBJECTID"

Ex:

Screen1.PNG

ISP_graynic
Frequent Contributor

Is there anyway to specify the output name of the file where the attachments are stored?  Right now each image is being output as a separate folders using a variation of the GlobalID for a name.  I'd like to have it output with just the file name.  Thanks!

0 Kudos
JakeSkinner
Esri Esteemed Contributor

The folder with the global id name is needed in order to successfully join the attachments to the feature class.