Select to view content in your preferred language

gis.content.search() exclude Deprecated items?

964
3
Jump to solution
12-12-2023 10:19 PM
Labels (1)
Kalu_Ribush
Occasional Contributor

Hello,

I've written code below to print a list of Web Maps in my Enterprise Portal.  

I'd like to exclude Deprecated Web Maps from the search results.  Can I add a parameter to do this?

Thanks in advance.

from arcgis.gis import GIS
from arcgis.mapping import WebMap
import arcpy

gis = GIS("pro")

service_contents = gis.content.search("*",item_type="Web Map", max_items = 1000)

print('Number of Web Maps found: ' + str((len(service_contents))))

#print the service title
for service in service_contents:
     print(service.title)

print("Finished")

0 Kudos
1 Solution

Accepted Solutions
ChristopherCounsell
MVP Regular Contributor

the content_status will show this 

https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html

try something like

from arcgis.gis import GIS
from arcgis.mapping import WebMap
import arcpy

gis = GIS("pro")

service_contents = gis.content.search("*", item_type="Web Map", max_items=1000)

print('Number of Web Maps found: ' + str(len(service_contents)))

# print the service title if the content_status is not deprecated
for service in service_contents:
item = gis.content.get(service.id)
if item.content_status != "deprecated":
print(service.title)

print("Finished")

View solution in original post

3 Replies
ChristopherCounsell
MVP Regular Contributor

the content_status will show this 

https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html

try something like

from arcgis.gis import GIS
from arcgis.mapping import WebMap
import arcpy

gis = GIS("pro")

service_contents = gis.content.search("*", item_type="Web Map", max_items=1000)

print('Number of Web Maps found: ' + str(len(service_contents)))

# print the service title if the content_status is not deprecated
for service in service_contents:
item = gis.content.get(service.id)
if item.content_status != "deprecated":
print(service.title)

print("Finished")

Kalu_Ribush
Occasional Contributor

Hi @ChristopherCounsell .  Thanks for response

Unfortunately I get this error message:

Kalu_Ribush_0-1702505257507.png

Any advice apprreciated.  Can I get it to ignore the error or skip that record?

 

0 Kudos
ChristopherCounsell
MVP Regular Contributor

Sorry I didn't test the script, but the content_status property is what you are looking for. It's likely not there for those without the property so you need to update script to handle it.

Try this one. It'll loop through and return the content_status. It can be empty, org_authoritative, deprecated, etc

from arcgis.gis import GIS

# Connect to your GIS using a specific profile or URL
gis = GIS("Home")

# Get the username of the logged-in user
user = gis.users.me.username

# Construct a query to search for web maps owned by the user
owner_query = "owner:" + user

# Search for web maps based on the query. Set max_items to -1 for all maps
webmaps = gis.content.search(query=owner_query, item_type="Web Map", max_items=10)

# Print the content status of each web map
for webmap in webmaps:
print(webmap.content_status)

 You'll need to add logic to your script to handle the property. e.g. here's one for authoritative content

https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-use-the-content-status-property...

 

0 Kudos