POST
|
yes we can do that. please post me your email address and I will email you. I dont want to post mine because web scrapers will pick it up and add me to junk mail. I am not too familiar with how this site works but maybe you can DM it to me as well. I have learned quite a few tricks with these REST service query scripts, so I would be happy to share them.
... View more
05-20-2019
12:22 PM
|
1
|
1
|
605
|
POST
|
yes you can have multiple URLS in the same script. Just be sure to change the name of the list (oidList) to something like oidList2 or the like, otherwise when it runs on the new URL it will overwrite what was in the original.
... View more
05-10-2019
11:37 AM
|
1
|
3
|
605
|
POST
|
i think the syntax is with the line above that, the line that starts with TO I think it is missing the closing "]" it should be TO = ['yourname@email.com']
... View more
04-10-2019
12:48 PM
|
0
|
7
|
429
|
POST
|
what line is it saying your error is in? i would also use pyscripter as your IDE, it gives much better information about errors. The script (lines 1-74) runs perfectly for me, i did not not mess with the smtp part at the bottom (lines 75-82) so i would imagine your syntax error is in lines 75 to 82. I would look up the documentation on SMTP and then make yours look like that.
... View more
04-10-2019
12:31 PM
|
0
|
9
|
429
|
POST
|
I took your script and rewrote some parts of it, the finished copy is located here: https://ufile.io/9emzw It queries your REST service and returns all records, from all the records it finds any record with a create date made in the last 10 days, it then creates a list of those and formats them into an email (body, subject, etc...) The rest of the email part you will have to put in your email server and credentials to complete. From: xxxxxxxxxxx\n To: xxxxxxxxxxxxxxxx\n Subject: You Have 4 New Service Request(s) Added to the GIS Records since: 2019-03-31 18:46:55\n \n1) Feature with ID # 0145 created on 2019-04-05 14:26:42 was added to the GIS Records. LOCATION: 1526 NW 89 CT\n\tSUMMARY: 201705896\r \n2) Feature with ID # 0145 created on 2019-04-05 20:20:23 was added to the GIS Records. LOCATION: 5200-5292 NW 84th Ave, Miami, Florida, 33166\n\tSUMMARY: TEST\r \n3) Feature with ID # 0144 created on 2019-04-05 20:23:20 was added to the GIS Records. LOCATION: 4800 NW 79th Ave, Miami, Florida, 33166\n\tSUMMARY: TEST\r \n4) Feature with ID # 0145 created on 2019-04-08 14:22:06 was added to the GIS Records. LOCATION: 8401 NW 53 TER\n\tSUMMARY: TEST\n' That is how the email will look (ignore the character tabs and escapes, outlook will format them as HTML)
... View more
04-10-2019
11:51 AM
|
0
|
11
|
429
|
POST
|
Can you turn the service back on, i tried to test your script but it is failing because it is disabled. but just from what i can see, you will need to change lines 35 and use your Created Date field instead of my ['Date_Notified'] field. Also you need to remove the zone = feat... line and fix line 40 to be something like if createDate > t: let me know when you turn the service back on and i will check some more.
... View more
04-08-2019
06:47 AM
|
0
|
14
|
429
|
POST
|
Send me the file with your changes and I will look at it. I am off for the weekend so it wont be till next week.
... View more
04-05-2019
02:59 PM
|
0
|
16
|
537
|
POST
|
here you go. i zipped the .py script and uploaded it here: https://ufile.io/cf0ha
... View more
04-05-2019
02:11 PM
|
0
|
18
|
537
|
POST
|
Ok so now you have built your oidList. It should contain a list of all the OBJECTIDs and their created_date. You can check that by typing oidList in your python window and seeing what appears. You now have to go line by line through the list and build your email. for me it was like this: For you it may be different. but think of it like this, now you have a list (oiddict) that holds your objectid and your date. now you open a for loop and go through each line and make your email message (TEXT in my case) by appending it to a new list (in my case its called newList) Then format an email msg, and then append the newList to it. then fire off the email. i can probably share with you my script but i will have to clean it up and remove all my local server information and email accounts.
... View more
04-05-2019
01:21 PM
|
0
|
20
|
537
|
POST
|
attributes are your fields, but when i am referencing them in this case I am talking about the parts of your data object. data is made up of geometry and attributes, and likewise the attributes are made up features. for feat in data['features'] <<- features here is to get at your attributes, ie you dont want geometry, just the features oidList.append(feat['attributes']) <-- each feature has attributes, append these attributes in the list LastDate = int(str([YOUR LAST DATE FIELD IN YOUR TABLE])[0:3] ^^ This is just making an INT (that is in UNIX EPOCH TIME) of your LAST DATE FIELD in YOUR RECORDS. For somereason you need to remove the trailing 000s that occur when using EPOCH TIME. This part is solely to get your time into a format that you can use datetime.datetime on to turn into a valid date to compare to your local tables. *** addressing your screenshot below, you would have to send me your entire code, maybe post it here or make a zip file from it. That error could be caused by any number of things.
... View more
04-05-2019
01:03 PM
|
0
|
22
|
537
|
POST
|
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.
... View more
03-20-2019
01:53 PM
|
0
|
24
|
537
|
POST
|
I dont fully understand your question. Are you asking for a return of all records where the last edit date field or the status field has not changed in 24-48 hours? If so the date field would be easy to do it on, just change your range of dates which you compare the last edited date to, ie show me all records where last edited date is less than than today - 2 (that is just psuedocode) If you are trying to compare records where the status has not changed in 2 days that will be more difficult. Also if i didnt understand your question please re-explain.
... View more
03-20-2019
12:58 PM
|
0
|
26
|
648
|
POST
|
Sorry for the late reply, just add i = 0 right after you declare the TIMEX variable. ie: t = datetime.datetime.now() - timedelta(hours=24) t = time.mktime(t.timetuple()) TIMEX = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(t)) i = 0 for oid in oidList: i = i+1 date = datetime.datetime.now().strftim .....
... View more
03-18-2019
12:09 PM
|
0
|
0
|
648
|
POST
|
It sounds like you want to loop through each record in oidList and output the OID and the Information. This can be done like this, loop through the oidList line by line, then output that to the email txt. The below code is pretty raw but i think it may help. The time stuff at the top was left in there since the subject requires it. t = datetime.datetime.now() - timedelta(hours=24) t = time.mktime(t.timetuple()) TIMEX = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(t)) for oid in oidList: i = i+1 date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" ) TMPTIME = oid['Closed_Date']/1000 TIME = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(TMPTIME)) TEXT = "\n\t" + str(i) + ") ZONE = " + str(oid['Zone']) + " Feature with ORACLE # " + str(oid['Oracle_ID']) + " was closed on " + str(TIME) +" " + " LOCATION: " + str(oid['Streets']) + "\n\tWORK SUMMARY: " + str(oid['Notes']) newList.insert(i,TEXT) print TEXT CURRENT=time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(t)) FROM = 'name@blah.com' #CHANGE TO YOUR NAME TO = ['name@blah.com'] #CHANGE THIS TO RECEPIENT, ADD MORE AFTER THE COMMA SUBJECT = '*** ' + str(i) +' Service Request(s) Closed in the GIS Records since: ' + str(TIMEX) + " ***" BODY = "Features with OBJECTIDs " + str(oidList) + " were Closed." PRIORITY = '2' message = """\ From: %s To: %s X-Priority: %s Subject: %s %s """ % (FROM, ", ".join(TO), PRIORITY, SUBJECT, '\r\n'.join(newList))
... View more
09-20-2017
11:04 AM
|
1
|
2
|
648
|
Title | Kudos | Posted |
---|---|---|
1 | 05-10-2019 11:37 AM | |
1 | 05-20-2019 12:22 PM | |
1 | 09-20-2017 11:04 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|