I added a feature and then ran the following:
import urllib2, json, urllib, datetime, time, smtplib
from datetime import timedelta
username = 'test'
password = 'test'
URL = 'https://services8.arcgis.com/XWI9YRo0bQGkCetU/arcgis/rest/services/service_e543c2e23b6d40a6b3cc03bba...'
uniqueID = 'objectid'
dateField = 'EditDate'
hoursValue = 1
fromEmail = 'test@esri.com'
toEmail = 'test@esri.com'
smtpServer = 'smtp.test.com'
portNumber = 25
oidList = []
try:
print('Generating Token')
tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
req = urllib2.Request(tokenURL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
token = data['token']
except:
token = ''
params = {'f': 'pjson', 'where': "1=1", 'outfields' : '{0}, {1}'.format(uniqueID, dateField), 'returnGeometry' : 'false', 'token' : token}
req = urllib2.Request(URL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
for feat in data['features']:
createDate = feat['attributes'][dateField]
createDate = int(str(createDate)[0:-3])
t = datetime.datetime.now() - timedelta(hours=hoursValue)
t = time.mktime(t.timetuple())
if createDate > t:
oidList.append(feat['attributes'][uniqueID])
print(oidList)
FROM = fromEmail
TO = [toEmail]
SUBJECT = 'New Features Added'
TEXT = "Features with {0}s {1} were added.".format(uniqueID, oidList)
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
if len(oidList) > 0:
smtpObj = smtplib.SMTP(host=smtpServer, port=portNumber)
smtpObj.sendmail(FROM, TO, message)
print "Successfully sent email"
smtpObj.quit()
I then received an e-mail:
Features with objectids [1034] were added.