|
DOC
|
@MonikaSamorajskatake a look at the below code: import requests, json, datetime, time, smtplib, math
from datetime import timedelta
from email.mime.text import MIMEText
# Disable warnings
requests.packages.urllib3.disable_warnings()
# Variables
username = 'jskinner_CountySandbox' # AGOL Username
password = '*******' # AGOL Password
URL = 'https://services.arcgis.com/dlFJXQQtlWFB4qUk/ArcGIS/rest/services/CitizenProblems/FeatureServer/0/query' # Feature Service URL
dateField = 'CreationDate' # Date field to query
hoursValue = 1 # Number of hours to check when a feature was added
fromEmail = '[email protected]' # Email sender
toEmail = ['[email protected]'] # Email receiver(s)
smtpServer = 'smtp.esri.com' # SMTP Server Name
portNumber = 25 # SMTP Server port
# Function to send email
def sendEmail():
SUBJECT = 'Problem Reported'
TEXT = "{0} was created with status {1} and has been assigned to {2}".format(typeProb, status, assignedto)
smtpObj = smtplib.SMTP(host=smtpServer, port=portNumber)
msg = MIMEText(TEXT)
msg['Subject'] = SUBJECT
msg['From'] = fromEmail
msg['To'] = ", ".join(toEmail)
smtpObj.sendmail(fromEmail, toEmail, msg.as_string())
print("Successfully sent email")
smtpObj.quit()
# 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'}
r = requests.post(tokenURL, data=params, verify=False)
response = json.loads(r.content)
token = response['token']
except:
token = ''
# Return largest ObjectID
whereClause = '1=1'
params = {'where': whereClause, 'returnIdsOnly': 'true', 'token': token, 'f': 'json'}
r = requests.post(URL, data = params, verify = False)
response = json.loads(r.content)
try:
response['objectIds'].sort()
except Exception as e:
print("Error: {0}".format(e))
count = len(response['objectIds'])
# Query service and check if editDate time is within the last hour
if count < 1000:
params = {'f': 'pjson', 'where': "1=1", 'outFields' : '*', 'returnGeometry' : 'false', 'token' : token}
r = requests.post(URL, data=params, verify=False)
response = json.loads(r.content)
for feat in response['features']:
typeProb = feat['attributes']['probtype']
status = feat['attributes']['status']
assignedto = feat['attributes']['assignedto']
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:
sendEmail() Where I'm creating choosing which fields to include in the e-mail is the below section: JakeSkinner_0-1617889235018.png I'm selecting fields probtype, status, and assignedto. The e-mail is sent through a function where these new field variables are included in the message: JakeSkinner_1-1617889427464.png
... View more
04-08-2021
06:44 AM
|
0
|
0
|
18641
|
|
DOC
|
@Danielle_Journey You would need to send the e-mail as you iterate through the features. One way to do this is by moving the code to send the e-mail into a function. In the for loop, you can call the function and send the appropriate e-mail. Try the following: import requests, json, datetime, time, smtplib, math
from datetime import timedelta
from email.mime.text import MIMEText
# Disable warnings
requests.packages.urllib3.disable_warnings()
# Variables
username = 'jskinner_CountySandbox' # AGOL Username
password = '**********' # AGOL Password
URL = 'https://services.arcgis.com/dlFJXQQtlWFB4qUk/arcgis/rest/services/CitizenProblems/FeatureServer/0/query' # Feature Service URL
uniqueID = 'OBJECTID' # i.e. OBJECTID
dateField1 = 'CreationDate' # Date field to query
dateField2 = 'EditDate' # Date field to query
hoursValue = 1 # Number of hours to check when a feature was added
fromEmail = '' # Email sender
smtpServer = '' # SMPT Server Name
portNumber = 25 # SMTP Server port
# Create empty list for uniqueIDs
oidList = []
updateFC = []
# Function to send email
def sendEmail(typeProb, status, assignedto):
SUBJECT = 'Status Updated - Murphy Citizen Problem Reporter'
html = """\
<html>
<body>
<p font-family: Arial>A "{0}" problem has been updated!</p>
<p><b>Problem Overview:</b></p>
<p>Status Update: {1}</p>
<p>Assigned To: {2}</p>
<p>Please allow 72 hours for a City of Murphy employee to contact you regarding this problem. You can also check the progress of your problem here:</p>
<p><a href="https://murphytx.maps.arcgis.com/apps/CrowdsourceReporter/index.html?appid=6200a42374604a91b5a3956951518abe" target="_blank">Murphy Citizen Problem Reporter</a>
</p>
<p>Thank you,</p>
</body>
</html>
<td style="color:DarkGreen; font-family: Arial, sans-serif; font-size: 14px;">
<b>City of Murphy</b><br />
<a href="mailto:[email protected]">[email protected]</a><br />
</td>
""".format(typeProb, status, assignedto)
smtpObj = smtplib.SMTP(host=smtpServer, port=portNumber)
msg = MIMEText("alternative")
msg = MIMEText(html, "html")
msg['Subject'] = SUBJECT
msg['From'] = fromEmail
msg['To'] = pocemail
smtpObj.sendmail(fromEmail, pocemail, msg.as_string())
print("Successfully sent email")
smtpObj.quit()
# 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'}
r = requests.post(tokenURL, data=params, verify=False)
response = json.loads(r.content)
token = response['token']
except:
token = ''
# Return largest ObjectID
whereClause = '1=1'
params = {'where': whereClause, 'returnIdsOnly': 'true', 'token': token, 'f': 'json'}
r = requests.post(URL, data = params, verify = False)
response = json.loads(r.content)
try:
response['objectIds'].sort()
except Exception as e:
print("Error: {0}".format(e))
OIDs = response['objectIds']
count = len(response['objectIds'])
iteration = int(response['objectIds'][-1])
minOID = int(response['objectIds'][0]) - 1
OID = response['objectIdFieldName']
# Query service and check if editDate time is within the last hour
if count < 1000:
params = {'f': 'pjson', 'where': "1=1", 'outFields' : '*', 'returnGeometry' : 'false', 'token' : token}
r = requests.post(URL, data=params, verify=False)
response = json.loads(r.content)
for feat in response['features']:
pocemail = feat['attributes']['pocemail']
category = feat['attributes']['category']
typeProb = feat['attributes']['probtype']
createDate = feat['attributes'][dateField1]
editDate = feat['attributes'][dateField2]
status = feat['attributes']['status']
assignedto = feat['attributes']['assignedto']
if editDate is not None and editDate != createDate:
editDate = int(str(editDate)[0:-3])
t = datetime.datetime.now() - timedelta(hours=hoursValue)
t = time.mktime(t.timetuple())
if editDate > t:
sendEmail(typeProb, status, assignedto)
s = editDate / 1000.0
s2 = createDate / 1000.0
# dFormat = "%d-%m-%Y %h:%m"
d = datetime.datetime.fromtimestamp(s).strftime("%m-%d-%Y %H:%M %p")
d2 = datetime.datetime.fromtimestamp(s2).strftime("%m-%d-%Y %H:%M %p")
print(d)
print(d2)
... View more
03-31-2021
12:39 PM
|
0
|
0
|
18729
|
|
DOC
|
@ToddMcNeilyou can use ArcGIS Pro's Delete Rows and Append GP tools instead. They will work on a feature service just as if it were a feature class.
... View more
03-30-2021
07:24 AM
|
0
|
0
|
13237
|
|
POST
|
@JoeMagnottaI recommend using the following script rather than performing an overwrite of the feature service: https://community.esri.com/t5/arcgis-online-documents/overwrite-arcgis-online-feature-service-using-truncate-and/ta-p/904457
... View more
03-29-2021
02:18 PM
|
1
|
1
|
7738
|
|
POST
|
@ToddMcNeilI would recommend using ArcGIS Pro's Delete Rows and Append tools, rather than an overwrite. These tools will work the same on a feature service just as if it were a feature class.
... View more
03-29-2021
02:17 PM
|
0
|
0
|
4958
|
|
POST
|
Hi @PlaninforAdmin , 1. You can accomplish that with GeoEvent. Specifically using GeoFences within GeoEvent 2. You may be able to accomplish what you're looking for with ArcGIS Dashboards
... View more
03-24-2021
06:58 AM
|
0
|
0
|
990
|
|
POST
|
@RosieCampbell, if this worked previously, I would recommend reaching out to Tech Support as this may be a bug. They can log the bug for you, so that the product team is aware.
... View more
03-24-2021
06:39 AM
|
0
|
0
|
2327
|
|
POST
|
Hi @GrantBenn1 , You could simply use the Append tool in ArcGIS Pro. It accepts feature services as if they were feature classes.
... View more
03-24-2021
06:04 AM
|
0
|
4
|
2650
|
|
POST
|
It may be easier to do this with a script rather than the Field Calculator. Ex: import arcpy
table = r"C:\TEMP\PYTHON\Test.gdb\XY"
nameDict = {}
with arcpy.da.SearchCursor(table, ["NAME"]) as cursor:
for row in cursor:
if row[0] not in nameDict.keys():
nameDict[row[0]] = 0
else:
nameDict[row[0]] = 1
del cursor
with arcpy.da.UpdateCursor(table, ["NAME", "Field"]) as cursor:
for row in cursor:
row[1] = nameDict[row[0]]
cursor.updateRow(row)
del cursor Result: JakeSkinner_0-1616590859062.png
... View more
03-24-2021
06:01 AM
|
3
|
0
|
5769
|
|
POST
|
Here is a service you can test with: https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0/query Input Geometry: -100.3858152,38.4981439 Spatial Reference: 4326 Distance: 2000 Units: Meters This should return 2 points.
... View more
03-16-2021
07:18 AM
|
1
|
1
|
15049
|
|
POST
|
1. What is the coordinate system of the service? Have you tried using the same coordinate type (i.e. meters)? 2. What is the geometry type of the service? i.e. polygon If you are working with polygons or lines, have you tried changing the Spatial Relationship to Intersects?
... View more
03-16-2021
06:34 AM
|
1
|
1
|
15054
|
|
POST
|
Hi @Jonathan1517 , what is the coordinate system of your service? The coordinates you are specifying are WGS 84. However, these will default to whatever your coordinate system of your service is in. Try specifying 4326 for the Input Spatial Reference parameter.
... View more
03-16-2021
05:40 AM
|
1
|
0
|
15092
|
|
POST
|
@JaredPilbeam2 try using the publishParameters parameter in the publish call. You'll need this info if you're trying to publish the CSV as a feature service. Ex: csv_layer = csv_item.publish(publishParameters={"type":"csv","name":"XY_Locations","locationType":"coordinates","latitudeFieldName":"Latitude","longitudeFieldName":"Longtidue"}) The above is publishing a CSV to a feature service called XY_Locations. It's creating the spatial content using coordinates from fields Latitude and Longitude.
... View more
03-10-2021
09:54 AM
|
0
|
2
|
7297
|
|
DOC
|
@DuncanHornby thanks for getting back to me. Even after making your changes, the script still produces errors. I found out from a colleague that you cannot have multiple process write to the same File Geodatabase. Are you writing the output to a File Geodatabase? I was able to get the multiprocessing to work by creating new layer files, however, this did not seem to be more performant. The multiprocessing took longer to perform the multiple solves, compared to sending multiple facilities and performing one solve.
... View more
03-10-2021
08:20 AM
|
0
|
0
|
15621
|
|
DOC
|
@DuncanHornby I was referring to the feature class only having 1 point. Here is the data and script if you wanted to take a look.
... View more
03-05-2021
11:07 AM
|
0
|
0
|
15678
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-08-2026 12:27 PM | |
| 4 | 05-07-2020 05:14 PM | |
| 1 | 03-25-2026 04:16 AM | |
| 1 | 03-16-2026 01:00 PM | |
| 1 | 12-22-2025 10:39 AM |
| Online Status |
Online
|
| Date Last Visited |
Tuesday
|