import arcpy from arcgis.gis import GIS from arcgis.features import FeatureLayerCollection # Connect to your portal using SSO portal_url = "https://yourportal.com/portal" gis = GIS(portal_url, auth="PRO") # Uses the active ArcGIS Pro session for SSO # Define the REST service URL rest_service_url = "https://ws.lioservices.lrc.gov.on.ca/arcgis2/rest/services/LIO_OPEN_DATA/LIO_Open01/MapServer" # List of layer numbers to upload layer_numbers = [0, 1, 2, 3, 4, 5, 6] # Adjust the list as needed # Loop through each layer and publish as an ArcGIS web service for layer_number in layer_numbers: layer_url = f"{rest_service_url}/{layer_number}" # Create Feature Layer Collection flc = FeatureLayerCollection(layer_url, gis) # Publish as a new web service on the portal flc.manager.publish( service_name=f"LIO_Layer_{layer_number}", service_type="feature", capabilities="Query" ) print("All layers have been published as ArcGIS web services.")