Run Python API script as scheduled task?

7061
34
04-18-2018 01:38 PM
ShawnHibbs1
New Contributor II

I have created a script that updates a feature service through the Python API in Jupyter Notebooks. I was wondering how I can run this as a scheduled task? 

34 Replies
DanPatterson_Retired
MVP Esteemed Contributor

I see nothing in the docs.... https://esri.github.io/arcgis-python-api/apidoc/html/index.html

nor in the sample notebooks https://developers.arcgis.com/python/sample-notebooks/

can the script be run as a general scheduled task?

0 Kudos
RohitSingh2
Esri Contributor

The script can be run as a genera scheduled task using Task Scheduler on Windows and cron on Linux.

You could follow the blog post at https://www.esri.com/arcgis-blog/products/product/analytics/scheduling-a-python-script-or-model-to-r...  for tips on how to do this except that you'd use the Python.exe from the environment that has ArcGIS API for Python installed in it. Refer to Schedule [Virtualenv Dependent] Python Script with Windows Task Scheduler - Super User for how to do this with conda.

ShawnHibbs1
New Contributor II

How do I find the environment where the API is installed?

0 Kudos
JohnYaist1
Esri Contributor

Hi Shawn Hibbs  - Open a command prompt and type:

conda info -e

 This will output a list of all your environments and the path to where they are stored.

You can also search for the arcgis package in a specific environment with the following command:

conda list -n myenv arcgis
PhilipFrancis
New Contributor II

Respectfully folks, please be careful when you are discussing the term environment in such a context. A given user has multiple environment contexts in an OS. As a direct comment to the above statement, conda does not know everything about the user's environment; FURTHERMORE, the environment settings that a user is given at a CLI can be quite different from when run as a task.

0 Kudos
vonmoosa
MVP

Did you find a solution to this? I'm looking for a way to run Jupyter .ipynb file on a daily basis.

0 Kudos
vonmoosa
MVP

How would I schedule my .ipynb to run daily? Do you have an example of how I can achieve this?

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

There's no obvious benefit to run notebook as a backstage task. you can copy all the code into a python script file (.py) then run it in the task scheduler.

vonmoosa
MVP

I have found the only way to download a hosted feature service table with attachments using Python is with the ArcGIS API. This will only work as a .ipynb and not as a .py. I'm aware that I can run .py files on task scheduler but have not found a solution to run a .ipynb on some sort of scheduler.

0 Kudos