DOC
|
Hi Jake Skinner, I would like to receive an e-mail with information including all hanges which have been made in the FS. Basically, I would like to set up the script to detecting the changes in the Feature Class, first related table and the second related table as well. For example, in FC there is location off traffic lights on the road, but someone surveyed this part of the road and add the new traffic light, and in the same time the same person added a new defect for the different traffic light. So I would like to receive the e-mail which says that the feature with Object ID number 5 has been added to the FC and the new defect with the object id 25 has been added to the related table. Do you think is it possibile? Monika
... View more
12-11-2019
08:25 AM
|
0
|
0
|
9048
|
DOC
|
Jake Skinner I managed to work the script. Thanks. Is there a possibility to change that the script will be looking for the changes in the Feature Services and in related tables? So instead of if it will be and function? Any thoughts?
... View more
12-10-2019
01:52 AM
|
0
|
0
|
9048
|
DOC
|
Hi Jake Skinner, I have just tried corrected script, and I've got the error message. See below: Error: 'NoneType' object has no attribute 'sort' I have shared the FC in the group, which you have an access to. Any thoughts?
... View more
12-06-2019
07:26 AM
|
0
|
0
|
9048
|
DOC
|
Hi Jake Skinner, here is my code. I have tried to run it, but there is still some erroe message. The error message is like below: line 41 whereClause = '1=1' ^ IndentationError: unindent does not match any outer indentation level Any thoughts? import requests, json, datetime, time, smtplib
from datetime import timedelta
# Disable warnings
requests.packages.urllib3.disable_warnings()
# Variables
username = '**********' # AGOL Username
password = '**********' # AGOL Password
URL = ['https://arcgis.egis.fr/arcgis/rest/services/MMA_CSQ/CSQ_RAM_FRACAS_DesignSys_Equipment_Pt/FeatureServer/0/query', 'https://arcgis.egis.fr/arcgis/rest/services/MMA_CSQ/CSQ_RAM_FRACAS_DesignSys_Equipment_Pt/FeatureServer/3/query','https://arcgis.egis.fr/arcgis/rest/services/MMA_CSQ/CSQ_RAM_FRACAS_DesignSys_Equipment_Pt/FeatureServer/4/query'] # Feature Service URL
uniqueID = 'objectid' # i.e. OBJECTID
dateField = 'last_edited_date' # Date field to query
hoursValue = 1 # Number of hours to check when a feature was added
fromEmail = '**********' # Email sender
toEmail = '***********' # Email receiver
smtpServer = 'smtp.gmail.com' # SMPT Server Name
portNumber = 465 # SMTP Server port
for URL in URLs:
if URL.split("/")[-2] == 0:
layerName = 'PropertyDamage'
elif URL.split("/")[-2] == 1:
layerName = 'RelatedTable'
# Create empty list for uniqueIDs
oidList = []
# Generate AGOL token
try:
print('Generating Token')
tokenURL = 'https://egisenv.maps.arcgis.com/home/groups.html/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'https://egisenv.maps.arcgis.com/home/groups.html'}
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 last_edited_date time is within the last hour
if count < 1000:
params = {'f': 'pjson', 'where': "1=1", 'outFields' : '{0}, {1}'.format(uniqueID, dateField), 'returnGeometry' : 'false', 'token' : token}
r = requests.post(URL, data=params, verify=False)
response = json.loads(r.content)
for feat in response['features']:
createDate = feat['attributes'][dateField]
if createDate is not None:
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])
else:
y = minOID
x = minOID + 1000
ids = response['objectIds']
newIteration = (math.ceil(iteration/1000.0) * 1000)
while y < newIteration:
if x > int(newIteration):
x = newIteration
where = OID + '>' + str(y) + ' AND ' + OID + '<=' + str(x)
print('Querying features with ObjectIDs from ' + str(y) + ' to ' + str(x))
params = {'f': 'pjson', 'where': where, 'outFields' : '{0}, {1}'.format(uniqueID, dateField), 'returnGeometry' : 'false', 'token' : token}
r = requests.post(URL, data=params, verify=False)
response = json.loads(r.content)
for feat in response['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])
x += 1000
y += 1000
print(oidList)
# Email Info
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.login("**********", "**********")
FROM = '*************'
TO = ['*************']
SUBJECT = 'New Features Added'
TEXT = "Features with {0}s {1} were added to {2}.".format(uniqueID, oidList, layerName)
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
# If new features exist, send email
if len(oidList) > 0:
smtpObj = smtplib.SMTP(host=smtpServer, port=portNumber)
smtpObj.sendmail(FROM, TO, message)
print("Successfully sent email")
smtpObj.quit()
... View more
12-06-2019
05:39 AM
|
0
|
0
|
9048
|
POST
|
Hello everyone, I work as a GIS technician is a railway industry. Currently I am responsible for creating a Web based GeoApplication which allows people to collect information directly on site. To achive this I have created a Feature Service which is stored on Geodatabase enterprise and using Arc GIS Online publish with the possibility to edit data using "Collector for ArcGIS". The structure of the GeoApplication is as following: 1. Feature Service contain "Feature Class" and two related tables (one table is realted directly to feature class, the second one is related to the first table, both relationships are define as 'one to many'). Some of the fields are string type, some of them are data type and some of them are long/short integer type. 2. Web Map / Web Application with the possibility to edit new information to the related tables 3. Web Application with Dashboards operation showing statistics from related tables. My goal is to create third table, where I will have information from three different sources: some columns from 'feature class', some columns from first related tables and some informations from second related table. I would like to keep relationships between information, so for example if I have one object in 'feature class' and two seprate information in the table related to the same object, I would like to populate information from 'feature class' for those two information and also attached some information from second table. All those information will be updated regurarly but people working on site, so it is necessary to create a geoprocessing tool which I can publish on Web Application and launch every time when I have some changes. Unfortunatelly I don't know Python so I am not able to achive it using Python script which I can publish as a geoprocessing tool. Does anyone had some similar issue and know how to help me or would like to help with the code? I would be gratefull for any ideas or help with the issue! Thanks.
... View more
12-04-2019
06:58 AM
|
0
|
1
|
858
|
DOC
|
Jake Skinner yes, you are right. I have just shared Feature Service in the group, if you want to check it. I have tried the script with your changes, but i have received this error message: line 118 if len(oidList) > 0: ^ IndentationError: unexpected indent Do you know what can cause this issue?
... View more
12-03-2019
09:46 AM
|
0
|
0
|
9048
|
DOC
|
Jake Skinner I have invited you yo the group. So the Feature Service contain one feature class with the equipment location and thwo related tables. One table is related to the Feature Class and the other table is related the the first The feature service is editable of-course. In the e-mail I would like to have the information depending on what has been changed, when the new feature was added to the feature class I would like to receive an e-mail which says that the "oOBJECTID" number 1 (for example) has been added, when the information in related table has been changed I would like to have the information that "objectid" nr 1 in related table has added. Please let me know if you understand my request. Monika
... View more
12-02-2019
08:21 AM
|
0
|
0
|
9048
|
DOC
|
Hi Jake Skinner Ideally I woul like to have more information, like two more fields, but I think this script is looking for the "OBJECTID" field and the information about "OBJECTID" is enough for me, as this is probably the only uniqeid which I have in the service. Are you able to help me with the code to achive that? Wishes, Monika
... View more
12-02-2019
03:40 AM
|
0
|
0
|
9048
|
DOC
|
Hi, thanks for the advice. I also would like to ask about how to add the information to the e-mail about the changes. I mean, when the script detects some changes, in the process when token is generating, I can see the number of the object which has been changed. Can you please advice how can I add this nformation to the e-mail which is genetared atomatically? Thanks again for any help.That is really helpfull for me. Wishes, Monika
... View more
11-28-2019
02:49 AM
|
0
|
0
|
7441
|
DOC
|
Hi, I've got another question. This script is looking for the created date and according to this field it is detecting the features which had been changed. Can you advise how to modify the script in the way that the script will look for the changes in related tables and according to the field detected the features with changes. Monika
... View more
11-26-2019
08:45 AM
|
0
|
0
|
7441
|
DOC
|
Thanks, now it is working with my gmail account. Monika
... View more
11-21-2019
10:56 AM
|
0
|
0
|
7441
|
DOC
|
Hi Jake, I tried to run the script with my personal account which is on gmail SMTP, but unfortunatelly I am having another issue. This time it is saying : raise SMTPSenderRefused(code, resp, from_addr) smtplib.SMTPSenderRefused: (530, b'5.7.0 Must issue a STARTTLS command first. p9sm20460115wrs.55 - gsmtp', 'msamorajska@gmail.com') I was searching for the solution on the Internet, and I found that I should provide credentials for my gmail account. I should say, that credentials for AGOL account and for gmail accout are different, and can you advice where should I add these information? Or do you have another explanation of my issue? Thanks in advance for your help! Monika
... View more
11-20-2019
01:07 AM
|
0
|
0
|
7441
|
DOC
|
Hey, thank you so much for your help. I am really appreciated for that. Wishes, Monika
... View more
11-18-2019
07:28 AM
|
0
|
0
|
7441
|
DOC
|
Hey Jack, thank you very much for your help!. I've got one more issue, and I was hoping you will help me understand what is the erros which I received from the script. Please see the information below: sock.connect(sa) OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions I am thinking that this issue can be on my firewall and no permission for sth, but before I will peak with the IT department, I would like to understand what exaclty I should tell them to fix this error. Wishes, Monika
... View more
11-18-2019
06:40 AM
|
0
|
0
|
7441
|
DOC
|
Hey Jake, much appriaciated for your help. Script works right now, it recognize that the new feature was added by, because I have some server connection issues it doesn't send me an email. I will discuss this issue with my IT department. I was just wondering, is it possibile to change the script, especially line 13 where is dateField = "created_date" to "last_edited_date" so the script can show all the modification, not only new features in the FC. Or is it more complicated than I think? Wishes, Monika
... View more
11-18-2019
06:20 AM
|
0
|
0
|
7441
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|