Select to view content in your preferred language

Using Python to extract all web services's last modified date

1016
4
10-25-2023 04:15 PM
SH013
by
Regular Contributor

As I explore the ArcGIS API for Python, I'm trying to find a way to extract specific details from all my web services at once. Despite my efforts, I haven't found a straightforward solution. This may sound a little bit silly on my end, but my primary objective is to retrieve the 'last modified' dates of each service under my purview. While I've been able to access this data through the admin REST endpoint, I'm unsure how to extract this using Python. Any insights or guidance on how to accomplish this in Python would be greatly appreicated.

 

Thanks in advance

Sam

Python learner

0 Kudos
4 Replies
CarstenB_orsted
Occasional Contributor

Hi Sam,

you could do something like this in the Python API (untested and written from memory, check the docs)

from arcgis.gis import GIS
from datetime import datetime
 
gis = GIS(.......)
items = gis.content.search("*") 
for item in items:
    d = datetime.fromtimestamp(item.modified/1000)
print(f"Item {item.title} was modified {d}")

 

Alternatively you can call the REST interface using the requests module in Python. I usually do a mix of both, but using RESTmore and more!

Regards

Carsten

 

 

0 Kudos
DonMorrison1
Frequent Contributor

Do you mean "last modified" for the ArcGIS Item or for the associated data? I have some code that tries to find the last time the data was changed. It only works for hosted feature layers. It does not work on feature layers proxied to an ArcGIS server REST service. For those I resort to detecting when the record count changes - not perfect but good enough.  Of course if edit tracking is turned on then that makes it easy but I don't own the feature layers so I can't do that.

 

 

datetime.datetime.fromtimestamp(int(arcgis.features.FeatureLayer(<feature_layer_url>).properties['editingInfo']['dataLastEditDate'])/1000)

 

 

0 Kudos
SH013
by
Regular Contributor

I apologize for leaving this discussion open for a while. To give you more context, I am attempting to go through all of the services to extract a bulk attribute called 'lastModified'. This attribute will provide me with information on when each service was last published. I was initially trying to accomplish this task through the ArcGIS API, but I'm still struggling to figure it out.

0 Kudos
DavidSolari
Frequent Contributor

It looks like the "modified" property on each service item aligns with when it was last updated. You'll get some false positives for items that were edited after the service was overwritten but this should be good enough for most purposes. Take another look at Carsten's code for tips on getting the date out in a readable format.

0 Kudos