Automate Field Value Changes on Date

598
1
05-10-2014 09:09 AM
deleted-user-o0qo22IL6bb6
New Contributor II
Hello All,

I an woefully inadequate when it comes to developing Python code.  I am nearing completion of the AGOL Polling Place Finder application for 10.2 with some relatively basic customizations.  I do however want to include a status (open / closed) field for each individual polling location and, ideally, I would like to have that status automatically change to the applicable value on an election day.  It would be even better if those values changed during set hours (polls are open from 6am -8pm).

I have fields for next election date, as well as poll opening and closing times.  I just lack the Python skills to put together the necessary function to automate the process.

Any help would be most appreciated.

Cheers.

Jason
Tags (2)
0 Kudos
1 Reply
MattEiben
Occasional Contributor
In order to test for the date and time, you can use the datetime module.

A couple code examples:

import datetime

date = datetime.datetime.now()

# Access your date attributes
print date.day
print date.month
print date.year

>>> # Print a formatted date string
>>> print date.strftime("%m/%d")
>>> '05/10'

# Test if between 6am and 8pm
if 6 < date.hour < 20:
 print "It is election time"


You could use some of the above methods to test for date and hour and change your field attributes accordingly through tools such as Calculate Field or an Update Cursor.
0 Kudos