repStr = 35*" " + "<!--" + searchText + "-->" + '<value userlist="' + NewString + """all">summary_""" + fieldName + " = '[value]\'</value>""" + "\n"
<!--replace1_start--><value userlist="value1, value2, all">summary_Milestone_Date = '[value]'</value>
# Import arcpy module import arcpy,shutil,fileinput,io # Local variables: summary = "\\\\mcflight01\\MCFlightData\\HGIS\\Data\\data_4_temp_services.gdb\\summary" # my dataset I'm searching against temp_path = "D:\\baks\\dont_use\\temp.gdb\\" config_file = "\\\\gis01\\C\\inetpub\\wwwroot\\WCH_WIDS_Status\\widgets\\eSearch\\eSearchWidget.xml" ifile = "D:\\baks\\dont_use\\eSearchWidget_template.xml" ofile = "D:\\baks\\dont_use\\eSearchWidget.xml" # Overwrite pre-existing files arcpy.env.overwriteOutput = True # copy config file to a working copy shutil.copy2(config_file, ifile) def UniqueList(): DataList = [] NewString = '' temp_freq = temp_path + fieldName + "_freq" # # Process: Frequency to get unique list by fieldName # arcpy.Frequency_analysis(summary, temp_freq, fieldName, "") for row in arcpy.SearchCursor(temp_freq, "", "", fieldName): DataList.append(row.getValue(fieldName)) NewString += str(row.getValue(fieldName)) + "," # # Set value for replacement string # repStr = 43*" " + '<value userlist="' + NewString + """all">summary_""" + fieldName + " = '[value]\'</value>""" + "\n" # # Open file to read values # with open(ifile,"r") as infile: with open(ofile,"w") as outfile: # open file to be able to write to for i, line in enumerate(infile): if searchText in line: # Check to see if the searchtext is in this line line = repStr outfile.write(line) # If so, replace this line with the string value of repStr. outfile.close #close outfile infile.close #close infile shutil.copy2(ofile, ifile) #copy the outfile to the new infile so it doesn't clobber last changes # # List of field names and respective replace text. # Just add another fieldName/searchText pair and send to UniqueList() # # userlist for Milestone_Date fieldName = "Milestone_Date" print "processing ",fieldName searchText = "replace1" UniqueList() # userlist for FINAL_ROD_DEC_UNIT fieldName = "FINAL_ROD_DEC_UNIT" print "processing ",fieldName searchText = "replace2" UniqueList() # userlist for Note fieldName = "Note" print "processing ",fieldName searchText = "replace3" UniqueList() # userlist for Date fieldName = "Date" print "processing ",fieldName searchText = "replace4" UniqueList() print "Done"
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.