I don't know the man, but I love reading his posts. I am sure you will too.
The web address is: https://geonet.esri.com/blogs/dan_patterson
Enjoy.
import arcrest
if __name__ == "__main__":
username = "some account"
password = "some password"
csv_file = r"C:\Users\andr5624\Desktop\book1.csv"
sh = arcrest.AGOLTokenSecurityHandler(username, password)
admin = arcrest.manageorg.Administration(securityHandler=sh)
content = admin.content
usercontent = content.usercontent(username=username)
ip = arcrest.manageorg.ItemParameter()
ip.title = "Sample CSV"
ip.type = "CSV"
ip.tags = "tag1,tag3"
res = usercontent.addItem(itemParameters=ip,
filePath=csv_file)
itemId = res['id']
# Now you need to analyze the item to publish it
#
featureContent = content.featureContent
analyzeParams = arcrest.manageorg.AnalyzeParameters()
analyzeResult = featureContent.analyze(itemId=itemId, analyzeParameters=analyzeParams)
# Published based off the analyze function
#
if 'publishParameters' in analyzeResult:
pp = analyzeResult['publishParameters']
publishParams = arcrest.manageorg.PublishCSVParameters(name=pp['name'],
locationType=pp['locationType'],
layerInfo=pp['layerInfo'],
latitudeFieldName=pp["latitudeFieldName"],
longitudeFieldName=pp['longitudeFieldName'])
print usercontent.publishItem(fileType="csv",
publishParameters=publishParams,
itemId=itemId)
import os
import arcpy
from arcpy import env
def validate_fgdb(fgdb=env.scratchGDB):
"""
Checks to see if the FGDB isn't corrupt. If
the FGDB is corrupt, it then erases the database
and replaces it with a new FGDB of the same name.
Input:
fgdb - string - full path of the file geodatabase
Output:
Boolean
"""
try:
fgdb = str(fgdb)
if os.path.isdir(fgdb) and \
fgdb.lower().endswith(".gdb"):
print 'workspace possible fgdb'
desc = arcpy.Describe(fgdb)
if hasattr(desc, "workspaceFactoryProgID") and \
desc.workspaceFactoryProgID != "esriDataSourcesGDB.FileGDBWorkspaceFactory.1":
shutil.rmtree(fgdb, ignore_errors=True)
arcpy.CreateFileGDB_management(out_folder_path=os.path.dirname(fgdb),
out_name=os.path.basename(fgdb))
return True
elif hasattr(desc, "workspaceFactoryProgID") and \
desc.workspaceFactoryProgID == "esriDataSourcesGDB.FileGDBWorkspaceFactory.1":
return True
else:
return False
elif os.path.isdir(fgdb) == False and \
fgdb.lower().endswith(".gdb"):
arcpy.CreateFileGDB_management(out_folder_path=os.path.dirname(fgdb),
out_name=os.path.basename(fgdb))
return True
else:
return False
except:
arcpy.AddError(arcpy.GetMessages(2))