The script that is at the top of this page would be the one you want to use. You would have to change some things to match your field names and your REST Service URL of course.
Also the current script is searching for dates a little different, you would need to change the current setup
- import urllib2, json, urllib, datetime, time, smtplib
- from datetime import timedelta
-
- oidList = []
-
- URL = 'http://services.arcgis.com/Fz6JUji5ArUSDM/arcgis/rest/services/Airports/FeatureServer/0/query'
- params = {'f': 'pjson', 'where': "1=1", 'outfields' : 'OBJECTID, created_date', 'returnGeometry' : 'false'}
- req = urllib2.Request(URL, urllib.urlencode(params))
- response = urllib2.urlopen(req)
- data = json.load(response)
- for feat in data['features']:
- createDate = feat['attributes']['created_date']
- createDate = int(str(createDate)[0:-3])
- t = datetime.datetime.now() - timedelta(hours=1)
- t = time.mktime(t.timetuple())
- if createDate > t:
- oidList.append(feat['attributes']['OBJECTID'])
you want to change lines 6 to your URL, also change line 7 to , this will return all of the attribute fields, also you can use the where part to query only certain features (i will tell you more about this at the bottom)
- params = {'f': 'pjson', 'where': "1=1", 'outfields' : '*', 'returnGeometry' : 'false'}
and then you want to change createDate to your LastEditedDate field, since that is what you are comparing on.
I would imagine yours would be something similar to
- for feat in data['features']:
- LastDate = feat['attributes']['YOUR_LASTEDITED_DATEFIELD_NAME']
- LastDate = int(str(createDate)[0:-3])
- t = datetime.datetime.now() - timedelta(hours=48) #you want 48 hours since you are looking for 2 days
- t = time.mktime(t.timetuple())
- if LastDate < t: # if the last edit date is less (older) than today - 48 hours (ie 2 days ago)
- oidList.append(feat['attributes']) # i prefer this as it will append all attributes, not just the OBJECTID like the original
Once you have dumped the returns into the oidList you can access them by calling oidList['FIELDNAMEYOUWANT']
** alternatively you ignore the date compare in python and could use a SQL query in the params to only return records that havent been edited in the last 2 days
- params = {'f': 'pjson', 'where': "1=1", 'outfields' : '*', 'returnGeometry' : 'false'}
you would change the where part to something like this (this wont work because i am not sure the exact syntax for querying datefields in rest services because they use unix epoch time)
'where': "LAST_EDIT_DATE < TODAY()-2" # again this wont work, but it should give you an idea of what to look for.