|
POST
|
Line 13 is a little dense so here it is separated to be a little more clear. import datetime
import os
import requests
import time
indexHTML = requests.get("https://www.gosolarcalifornia.ca.gov/equipment/documents/").text
fileName = "Grid_Support_Inverter_List_Full_Data.xlsm"
fileNameHTML = '<td><a href="{0}">{0}</a></td>'.format(fileName)
fileNameHTMLIndex = indexHTML.find(fileNameHTML)
if fileNameHTMLIndex != -1:
dateStartIndex = indexHTML.find(">", fileNameHTMLIndex+len(fileNameHTML)) + 1
dateEndIndex = indexHTML.find("<", dateStartIndex)
webFileDate = indexHTML[dateStartIndex:dateEndIndex].strip()
webFileDate = datetime.datetime.strptime(webFileDate, "%Y-%m-%d %H:%M")
else:
raise Exception("Unable to find fileName {}".format(fileName))
localFilePath = r"your\local\path\here"
localFileDate = os.path.getctime(localFilePath)
localFileDate = datetime.datetime.strptime(time.ctime(localFileDate), "%a %b %d %H:%M:%S %Y")
if webFileDate > localFileDate:
print("File on the web is newer!")
# download web file to replace local file
... View more
01-03-2020
09:59 AM
|
0
|
0
|
1427
|
|
POST
|
Line 4 will return a -1 if fileNameHTML is not found in indexHTML. So, line 5 checks for the presence of a <td> tag with the filename. In the event it is found (the value is not -1), it then checks for the first ">" and the first "<" in indexHTML on lines 6 and 7. Using the returned indexes, it slices indexHTML, strips the leading and trailing white space, and formats the text into a datetime object. Yes, that's exactly right. That was the simplest way I could think (with builtin libraries) to get the text value of the tag in the HTML table. This does assume the filenames are all unique, which I think is safe. Once it finds the file name, it assumes the next tag will contain the date. I simplified this to just look for the first > (indiciating the last character of the opening tag) and the next < after that (indicating the first character of the closing tag). The value of the tag (the date) will be between those two characters. Hopefully that is clear and you can comment that section in a way that makes sense to you.
... View more
01-03-2020
08:26 AM
|
0
|
0
|
4943
|
|
POST
|
My code sample is comparing the date listed for the file on the website (not sure what date it is) with the created date for the file on your local drive. You can adjust the line with getctime() to getmtime() if you want the modified date instead. You might want to do some testing to make sure the file you download from the website has a created date either when it was downloaded or that matches what's listed on the website.
... View more
12-27-2019
07:49 AM
|
0
|
3
|
3518
|
|
POST
|
Correct. My method is only comparing file dates so it doesn't matter what the file actually is.
... View more
12-26-2019
09:33 AM
|
0
|
5
|
3518
|
|
POST
|
Here is kind of a hacky solution that just parses the file index page for the file you want and gets the date listed in the next cell of the same table row. You can then compare this date with the date of your local file to decide if you want to download it. import datetime
import os
import requests
import time
indexHTML = requests.get("https://www.gosolarcalifornia.ca.gov/equipment/documents/").text
fileName = "Grid_Support_Inverter_List_Full_Data.xlsm"
fileNameHTML = '<td><a href="{0}">{0}</a></td>'.format(fileName)
fileNameHTMLIndex = indexHTML.find(fileNameHTML)
if fileNameHTMLIndex != -1:
dateStartIndex = indexHTML.find(">", fileNameHTMLIndex+len(fileNameHTML)) + 1
dateEndIndex = indexHTML.find("<", dateStartIndex)
webFileDate = datetime.datetime.strptime(indexHTML[dateStartIndex:dateEndIndex].strip(), "%Y-%m-%d %H:%M")
else:
raise Exception("Unable to find fileName {}".format(fileName))
localFilePath = r"your\local\path\here"
localFileDate = os.path.getctime(localFilePath)
localFileDate = datetime.datetime.strptime(time.ctime(localFileDate), "%a %b %d %H:%M:%S %Y")
if webFileDate > localFileDate:
print("File on the web is newer!")
# download web file to replace local file Alternatively, just download the file and use the method Arne Gelfert mentioned to compare them for differences. The file isn't large so it shouldn't take excessively long to download and the logic is much simpler.
... View more
12-26-2019
09:00 AM
|
0
|
7
|
3518
|
|
POST
|
Is the scheduled task set to run as the GISAdmin user? We put our database connections in a common folder on the C: drive of the server instead of in a user folder.
... View more
12-24-2019
07:41 AM
|
0
|
0
|
4216
|
|
POST
|
If I understand correctly, you want a way to compare the created or modified date of two files? Here's one solution I found.
... View more
12-24-2019
07:37 AM
|
0
|
0
|
3518
|
|
POST
|
Great idea Arne Gelfert. Here's the equivalent for us Oracle folks. select A.table_name
from SDE.table_registry A
left outer join ALL_TABLES B
on A.table_name = B.table_name
where b.table_name is NULL
... View more
12-24-2019
07:24 AM
|
0
|
0
|
6385
|
|
POST
|
Just an observation of your script. You are importing all of arcpy, which includes arcpy.env and arcpy.da so you don't need to import those explicitly. Especially since you are still calling it as arcpy.env and don't appear to be using arcpy.da. This will do: import arcpy
import os
... View more
09-03-2019
08:20 AM
|
0
|
1
|
3779
|
|
POST
|
We used the About widget and put all of the attribution in there. ArcGIS Web Application
... View more
08-16-2019
08:05 AM
|
3
|
0
|
10673
|
|
POST
|
I'm creating a Python toolbox and want to host one of the tools as a geoprocessing service (ArcGIS 10.5.1). The required input is a GPFeatureLayer. The output is a CSV file to arcpy.env.scratchFolder, which ends up being the output directory of the service when published. The end user needs to run the script in ArcMap and choose an input layer that has a selection of features. This works fine as a local Python toolbox. However, when published as a service (using the "User defined value" as the parameter's input mode), the default value is a ScratchRecordSet layer that gets added to the map with a name like ToolName::parameter_name. Is there a way to prevent this ScratchRecordSet layer from appearing? ArcGIS Enterprise
... View more
07-17-2019
04:29 PM
|
0
|
0
|
948
|
|
POST
|
This is a tough one, which is why we mirror the folder structure our published services with a folder of map documents used to publish the services. You can see the location where the original mxd was published from using ArcGIS Server Manager to view the General tab of the service properties. The same thing is also in ArcCatalog service properties but it's on the Parameters tab. However, this won't do any good if the MXD has been moved or deleted since publishing. Edit: You might be able to find in your server directory at \arcgisserver\directories\arcgissystem\arcgisinput\ServiceFolderName\ServiceName.MapServer\extracted\v101 ArcGIS Enterprise
... View more
03-21-2019
07:48 AM
|
0
|
1
|
1679
|
|
POST
|
When using the Create Database User GP tool in ArcGIS 10.5.1 for an enterprise geodatabase in Oracle 12c, is it possible to use another user besides SYS?
... View more
03-14-2019
09:54 AM
|
0
|
1
|
950
|
|
POST
|
Revisiting this, I've simplified the code a little by creating the edit session outside the try...except so you don't have to check if it exists. edit = arcpy.da.Editor(sdeconnection)
print "edit created"
try:
edit.startEditing()
print "edit started"
edit.startOperation()
print "operation started"
# Perform edits
with arcpy.da.InsertCursor(fc, fields) as fc_icursor:
fc_icursor.insertRow(someNewRow)
edit.stopOperation()
print "operation stopped"
edit.stopEditing(True) ## Stop the edit session with True to save the changes
print "edit stopped"
except Exception as err:
print err
if edit.isEditing:
edit.stopOperation()
print "operation stopped in except"
edit.stopEditing(False) ## Stop the edit session with False to abandon the changes
print "edit stopped in except"
finally:
# Cleanup
arcpy.ClearWorkspaceCache_management()
... View more
02-26-2019
02:18 PM
|
8
|
1
|
11895
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | a month ago | |
| 1 | 10-23-2025 03:53 PM | |
| 1 | 04-28-2026 07:25 AM | |
| 1 | 03-19-2026 08:59 AM | |
| 1 | 02-12-2026 01:37 PM |