Schedule an Arcade Expression to run each day at a specified time using Python

614
4
Jump to solution
12-18-2020 09:26 AM
AlenO_Farrell
New Contributor II

Hi, I am Calculating a Field with an Arcade Expression which compares the date in a given field with today’s date and provides a result in months.  The result is calculated in to an existing field “Months at Current Stage”. I can run the Arcade Expression manually but I would like to automate this in Python. Is this possible in ArcGIS online Notebook using Python? New to Python, so any help would be appreciated!

1 Solution

Accepted Solutions
JoeBorgione
MVP Esteemed Contributor

You'll need to get familiar with the datetime module in python.  Here are a couple of links to point you in the right direction:

https://www.kite.com/python/answers/how-to-get-the-number-of-months-between-two-dates-in-python

https://gist.github.com/amalgjose/c767a4846d6ecaa3b6d7

 

That should just about do it....

View solution in original post

4 Replies
JoeBorgione
MVP Esteemed Contributor

Mixing metaphors; Arcade and Python.  I suggest just doing it all in python and run the script as scheduled task or as you suggest a notebook.

That should just about do it....
AlenO_Farrell
New Contributor II

Joe,

Thanks for the response to my question. I gather from your reply that this would be possible in Python which is great.

While I have the following, very simple, Arcade Expression, my difficulty is how to write a Python script that would achieve the same result. 

var startDate = Date($feature.Start_Date_of_Current_Stage);
var endDate = Date(Now());
var MACS = DateDiff(endDate, startDate, 'months');
return MACS;

I am completely new to Python and this will be my first Python script, so I appreciate the help.

Alen

 

 

0 Kudos
JoeBorgione
MVP Esteemed Contributor

You'll need to get familiar with the datetime module in python.  Here are a couple of links to point you in the right direction:

https://www.kite.com/python/answers/how-to-get-the-number-of-months-between-two-dates-in-python

https://gist.github.com/amalgjose/c767a4846d6ecaa3b6d7

 

That should just about do it....
AlenO_Farrell
New Contributor II

Thanks Joe, 

Much appreciated. I will post my progress in the new year.

0 Kudos