AnsweredAssumed Answered

Query on a hosted feature service I own?

Question asked by vonmoosa Champion on Jul 19, 2018
Latest reply on Jul 19, 2018 by vonmoosa

I want to modify the script below to pull data from a hosted feature service I own instead of a local .gdb. Does anyone have a solution?

import arcpy, datetime
arcpy.env.overwriteOutput = True

fc = r"G:\GIS\Anthony\Workspaces\Public Works\ApprovedApproachesTEST\New File Geodatabase.gdb\Approaches" # feature class
fn = r"G:\GIS\Anthony\Workspaces\Public Works\ApprovedApproachesTEST\output.txt" # save file name
today =
dte = today.strftime('%m/%d/%Y')

f = open(fn, 'w')

fields = ['Name', 'Approved'] # can add other fields such as Approved, if needed

whereClause = "Approved = 'Yes' AND Date_Approved = {}".format(dte)  # may need to modify, based on field type, how Y-N is stored

with arcpy.da.SearchCursor(fc, fields, where_clause=whereClause) as cursor:
    for row in cursor:
        f.write("{}\t{}".format(row[0], row[1])) # Name and Approved - to file
        print "{}\t{}".format(row[0], row[1]) # Name and Approved - to console if needed

print "Done"