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")
Solved! Go to Solution.
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")
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")
Hi @ChristopherCounsell . Thanks for response
Unfortunately I get this error message:
Any advice apprreciated. Can I get it to ignore the error or skip that record?
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