Hello everybody!
I would like to overwrite several layers from ArcGIS Pro to ArcGIS Online using arcpy. The layer names in ArcGIS Online and Pro are completly different from each other.
My idea was to assign the new layer in ArcGIS Pro with the old layer in ArcGIS Online via a dictionary. But I dont know how to proceed...
Could you please help me with that?
I'm very new to scripting. I used a lot from https://github.com/rooschu/overwrite-web-layers/blob/master/OverwriteWebLayers.py
and
https://pro.arcgis.com/en/pro-app/2.8/arcpy/sharing/featuresharingdraft-class.htm
My script so far is:
prjFolder = r"path"
prjPath = os.path.join(prjFolder, r"path to .aprx")
# Set login credentials
portal = "..."
user = "xyz"
password = "xyz"
# Assign name and location for temporary staging files
tempPath = prjFolder
#select layers in arcgis pro
layers = geoMap.listLayers()
service_name = []
for x in layers:
service_name.append(x.name)
#sharing draft
stringdraft = ".sddraft"
sddraft_filename = [x + stringdraft for x in service_name]
sddraft = os.path.join(tempPath, *sddraft_filename)
#sharing sd
stringsd = ".sd"
sd_filename = [x + stringsd for x in service_name]
sd = os.path.join(tempPath, *sd_filename)
# Connect to ArcGIS online
print("Connecting to {}".format(portal))
gis = GIS(portal, user, password)
print("Successfully logged in as: " + gis.properties.user.username + "\n")
# Assign environment and project, and create empty dictionaries
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
layerDict = {}
servDict = {}
# Populate map dictionary with map names and objects from earlier defined project
for layer in geoMap.listLayers ():
layerDict[layer.name] = layer
#select ArcGIS Online Web Layers
lyItems = gis.content.search(query="owner:{0}".format(user),item_type="Feature Layer", max_items=100)
ext= ["WFL1", "_Faelle", "genschaft"]
service_name = [item for item in lyItems if item.title.endswith(tuple(ext))]
Also when I try to create the both os.path.join() it doesn't create six diferent paths but one very long path with all my layers added.