<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Best way to monitor for new features in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/best-way-to-monitor-for-new-features/m-p/1012379#M5360</link>
    <description>&lt;P&gt;Hi, I'm looking for any tips on the best way to monitor an AGOL feature service for newly added features. Basically I have a public feature service that I want to monitor for when new features are added. I want to run some follow on scripts on new features only.&lt;/P&gt;&lt;P&gt;Right now, I think my best bet is to just set up a pythonanywhere script that runs every hour and checks the "created date" field for any features created in the last hour. Another option might be to create a custom "tracking field" that is NULL by default, then I create a script to check for features where this field is null, then when my script is finished I update this field to be not null.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are these my basic options?&lt;/P&gt;</description>
    <pubDate>Sun, 27 Dec 2020 11:16:08 GMT</pubDate>
    <dc:creator>lightpro</dc:creator>
    <dc:date>2020-12-27T11:16:08Z</dc:date>
    <item>
      <title>Best way to monitor for new features</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/best-way-to-monitor-for-new-features/m-p/1012379#M5360</link>
      <description>&lt;P&gt;Hi, I'm looking for any tips on the best way to monitor an AGOL feature service for newly added features. Basically I have a public feature service that I want to monitor for when new features are added. I want to run some follow on scripts on new features only.&lt;/P&gt;&lt;P&gt;Right now, I think my best bet is to just set up a pythonanywhere script that runs every hour and checks the "created date" field for any features created in the last hour. Another option might be to create a custom "tracking field" that is NULL by default, then I create a script to check for features where this field is null, then when my script is finished I update this field to be not null.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are these my basic options?&lt;/P&gt;</description>
      <pubDate>Sun, 27 Dec 2020 11:16:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/best-way-to-monitor-for-new-features/m-p/1012379#M5360</guid>
      <dc:creator>lightpro</dc:creator>
      <dc:date>2020-12-27T11:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to monitor for new features</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/best-way-to-monitor-for-new-features/m-p/1013842#M5390</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/416915"&gt;@lightpro&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I reckon the following script can help.&lt;/P&gt;&lt;P&gt;This is from &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;&amp;nbsp;which sends email when a feature is added to a hosted feature service.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import urllib2, json, urllib, datetime, time, smtplib
from datetime import timedelta

# Variables
username = 'jskinner_CountySandbox'        # AGOL Username
password = '******'    # AGOL Password

URL = 'https://services1.arcgis.com/vdNDkVykv9vEWFX4/arcgis/rest/services/address_errors/FeatureServer/0/qu...'       # Feature Service URL
uniqueID = 'OBJECTID'           # i.e. OBJECTID
dateField = 'CreationDate'      # Date field to query
hoursValue = 1                  # Number of hours to check when a feature was added

fromEmail = 'test@esri.com' # Email sender
toEmail = 'test@esri.com'   # Email receiver
smtpServer = 'smtp.gis.com'    # SMPT Server Name
portNumber = 25                 # SMTP Server port

# Create empty list for uniqueIDs
oidList = []

# Generate AGOL token
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 = ''

# Query service and check if created_date time is within the last hour
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 &amp;gt; t:
        oidList.append(feat['attributes'][uniqueID])

print(oidList)

# Email Info
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 new features exist, send email
if len(oidList) &amp;gt; 0:
    smtpObj = smtplib.SMTP(host=smtpServer, port=portNumber)
    smtpObj.sendmail(FROM, TO, message)
    print "Successfully sent email"
    smtpObj.quit()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other option is using &lt;STRONG&gt;webhooks&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use a webhook for feature service view (tile, scene, etc.), to receive notification for updates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-online/sharing-collaboration/how-to-create-a-hosted-feature-service-webhook/" target="_blank" rel="noopener"&gt;https://www.esri.com/arcgis-blog/products/arcgis-online/sharing-collaboration/how-to-create-a-hosted-feature-service-webhook/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope these give you some ideas.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Mehdi&lt;/P&gt;&lt;P&gt;======================================================================&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Please give a like if helpful and Accept as Solution if it's answered your query.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 02:57:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/best-way-to-monitor-for-new-features/m-p/1013842#M5390</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2021-01-05T02:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to monitor for new features</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/best-way-to-monitor-for-new-features/m-p/1014856#M5396</link>
      <description>&lt;P&gt;Excellent, this is great thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 21:21:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/best-way-to-monitor-for-new-features/m-p/1014856#M5396</guid>
      <dc:creator>lightpro</dc:creator>
      <dc:date>2021-01-07T21:21:27Z</dc:date>
    </item>
  </channel>
</rss>

