I've been trying to automate updating my organizations web-layers so i don't have to do it automatically, but I was having trouble making a model work so I decided to try moving it to python.
I have a geodatabase with all the files I want to use as sources, and the feature layers they match to all have the same name, so it should be easy to match them.
I have written this code, which runs fine until it get to the second for loop. Before I added the second for loop it actually ran with no errors but returned nothing. I have walked step by step through the code and the problem seems to be that it gets to the feature datasets, but then at ListFeatureClasses, it always returns null, even though all the datasets are full of feature classes.
I tried to use arcpy.da.Walk and pycharm says there is no such reference in arcpy.da and I can't even find any info on why that would be.
I feel like once I can get the data in properly, doing the truncate and append with be easy, but I'd need to get there first.
import arcpy
import os
workspace = r'D:\Master_GIS_Files\Data\Florence\Utilities\FlorenceUtilities.gdb'
def FCIterator():
with arcpy.EnvManager(workspace=workspace):
fdl= arcpy.ListDatasets()
featureclasses = arcpy.ListFeatureClasses(fdl)
for fds in fdl:
featureclasses.extend(arcpy.ListDatasets(fds))
for fc in arcpy.ListFeatureClasses(fds):
yield os.path.join(workspace, fds, fc), fc
def GetWebLayer(name):
from arcgis.gis import GIS
gis = GIS('https://city-of-florence.maps.arcgis.com/home', username="KitFlorence", password="Thorne!Florence27")
ttl = f"title:*{name}"
q = ttl + 'AND item_type="Feature Layer" AND "owner:' + gis.users.me.username + r'"'
fLayerz = [f for f in gis.content.search(query=q)][0]
if fLayerz:
fLayer = fLayerz[0]
flID = str(fLayer.id)
return flID
else:
pass
for path, Fname in FCIterator():
lID = GetWebLayer(Fname)
print(path, Fname)
print(lID)