Automate Publishing of Survey123 Project

3172
23
08-30-2021 11:49 AM
jaykapalczynski
Frequent Contributor

I have an existing project that has a few media files.  I have frequent updates to these media files as well as occasional form updates.  I need a python script that I can run via scheduler that will publish this project nightly.  I have read a bunch of posts but cant find anything clearly stated that shows how to do this.  Is there anyone out there that can help provide a solution?

0 Kudos
23 Replies
by Anonymous User
Not applicable

Hi @JamesKelly4 @jaykapalczynski @DougBrowning ,

Note that @ZacharySutherby  has provided an updated copy of the script using Python 3 and some other improvements. See this comment here: https://community.esri.com/t5/arcgis-survey123-questions/updating-csvs-in-agol-for-select-one-from-f...

Regards,

Phil.

jaykapalczynski
Frequent Contributor

What zip file?  I have to create a Zip file everytime?  

 

0 Kudos
by Anonymous User
Not applicable

Hi @jaykapalczynski,

If you are using either of the python scripts that are linked to the above comments to update CSV files or other media files, it downloads the Form item (which is a zip file), extracts it, you then update the items, and the script then re-creates the zip file again, and uploads its.

Note that this process does not update the XLSForm itself, the only way to do that is via publishing the survey again via Connect, as the xlsx file has to be converted to xml and other form item information updated. The script can only be used to update media files without publishing.

Regards,

Phil.

 

0 Kudos
jaykapalczynski
Frequent Contributor

Im confused....I know I have the correct Credentials but keep getting coming up with a NULL for the token I am trying to get via the script.

This returns NULL...any thoughts

print "token: " + json.dumps(agol_helper.token)

 

NOTE: I have ArcMap 10.8.1 installed.  I have python 2.7 and python 3.4 on my machine.  Could this be causing the issue?  If so is there a way that I can specify to use python 2.7?

It appears I am using 2.7.18

jaykapalczynski_1-1631034597924.png

 

 

print ("...Starting")
# initialize the portal helper class
# ago.py is part of the 10.3 python install
agol_helper = ago.AGOLHelper(portal_url)
print portal_url
print ("...Authenticating")
# login
print credentials['userName']
print credentials['passWord']
agol_helper.login(credentials['userName'], credentials['passWord'])

print "token: " + json.dumps(agol_helper.token)

print ("...Querying")
# get the name of the zip file
serviceInfo = getServiceDefinition(agol_helper.token, itemID)

 

 

Noting that I updated the "portal_url" parameter for my AGOL online account....line 11

 

 

# User Parameters
# ItemID of the Form item you want to update
itemID = "00da9adCr45f4f15b3443ecadd81vfgh"
# Local folder where the Form data will be downloaded (include a / at end of path)
download_folder = "C:/Users/tjv34534/Desktop/CWD_Project/Update_Media_Folder/"
# Updated file name (ie MyList.csv)
updated_file = "CheckQuery.csv"
# Folder path of the updated file (include a / at end of path)
source_loc = "C:/Users/tjv34534/Desktop/CWD_Project/Update_Media_Folder/UpdatedMediaFiles/"
# Address of your ArcGIS portal
portal_url = r"https://xxxxxx.maps.arcgis.com/"
# ArcGIS user credentials to authenicate against the portal (case sensitive)
credentials = {'userName' : 'xxxxx', 'passWord' : 'xxxxx'}
# ArcGIS portal security type (LDAP, NTLM, OAuth, Portal, PKI)
security_type = "Portal"

 

 

 

0 Kudos
by Anonymous User
Not applicable

Hi @jaykapalczynski,

As @ZacharySutherby points out in this post here and I mentioned in one of my comments above, the original update media folder script is now outdated and contains modules that have been superseded by the ArcGIS API for Python.

We have updated this script to use the ArcGIS API for python and the updated script is present in our Survey123-tools github repo

Regards,

Phil.

0 Kudos
jaykapalczynski
Frequent Contributor

OK I think I have this working from ArcGIS Pro on my Laptop....it appears to be updating and uploading this to AGOL.

Most Important

How do I automate it to run when I want it to.  I am new to using Pro and it appears to be baked into an ArcGIS Pro project?????

0 Kudos
DougBrowning
MVP Esteemed Contributor

Just stick this line in there and it will grab the credentials from Pro for you.

gis = GIS('pro')

Pro does not even have to be open.  Pro retains the token for 2 weeks.

But again as stated you should really switch gears to the new way and let this old way go.  Way easier.

0 Kudos
jaykapalczynski
Frequent Contributor

Thanks Doug

So if I have the code baked into an ArcGIS Pro project in a "New Notebook" tab how do I automate it to run nightly. 

It appears I can no longer use a .py file and use Task Scheduler to run it nightly.

 

jaykapalczynski_0-1631122096167.png

 

0 Kudos
jaykapalczynski
Frequent Contributor
  1. So I cannot use .py files and schedule any longer???
  2. I have to use ArcPro and Jupyter ???
  3. How do I automate the script running?
  4. Do I need to install ArcGIS Notebook Server to automate this? 
  5. Whats the difference between Jupyer in Pro and ArcGIS Notebook Server?
0 Kudos
DougBrowning
MVP Esteemed Contributor

No you can schedule.  I run this as a standalone script on schedule no problem.  It just goes and grabs the Pro credentials for you. 

0 Kudos