Append Data, Find Duplicate "key", Update other values using/search and updatecursor
I have a process which uses a JSON web-service to append all data, sometimes data is updated for one service request meaning that if SR-1, OID1 is created at 09:00AM with a quantity of 1 but then updated at 09:01AM as OID2 with a quantity of 2, I would like to keep OID1 and update the values from OID2 TO OID1 and delete the OID1 feature. I have a script which is partly functional that gets the count of duplicates and searches on those; but it is not deleting OID2.
import osimport sys import datetime import arcpyimport GetSRConfigimport jsonpickledef trace(): import traceback, inspect tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # script name + line number line = tbinfo.split(", ")[1] filename = inspect.getfile(inspect.currentframe()) # Get Python syntax error synerror = traceback.format_exc().splitlines()[-1] return line, filename, synerrordef GetDS(ds): d = time.clock() dt = d - ds return dtdef GetDSMsg(ds, format="%.3f s."): d = time.clock() dt = d - ds if(format==""): format = "%.3f s." return format % dtdef PrintException(): exc_type, exc_obj, tb = sys.exc_info() f = tb.tb_frame lineno = tb.tb_lineno filename = f.f_code.co_filename linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) print 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)def GetThisDir(): import inspect return os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))def GetDateTimeString(n = None): """ format a datetime to string """ if(n==None): s = time.strftime("%Y%m%d%H%M%S", time.localtime()) else: s = time.strftime("%Y%m%d%H%M%S", time.localtime()) if((isNumeric
==True) and ((n>4) and (n0): sWhereSelect = "" for oid in lOIDs: if(sWhereSelect==""): sWhereSelect = str(oid) else: sWhereSelect = sWhereSelect + "," + str(oid) sWhereSelect = OIDFldName + " in (" + sWhereSelect + ")" arcpy.SelectLayerByAttribute_management(flSDEData, "NEW_SELECTION", sWhereSelect) arcpy.DeleteFeatures_management(flSDEData) except: print(trace()) finally: if(pEditor!=None): pEditor.stopEditing(True)EDIT:
Here's the output
C:\Python27\ArcGIS10.2\python.exe E:/C_Drive_files/Administrator/311Request/UpdateSRDB.py10/01/2015 04:08:01UPDATE_DATE_DATE > OPEN_TIME_DATEE:\C_Drive_files\Administrator\311Request\data\ServiceRequest.sde\ServiceRequest.DBO.SO_SC1COUNT_NUMBERCYLA >= 1(16739, u'1-37298161')Process finished with exit code 0
أكثر...
I have a process which uses a JSON web-service to append all data, sometimes data is updated for one service request meaning that if SR-1, OID1 is created at 09:00AM with a quantity of 1 but then updated at 09:01AM as OID2 with a quantity of 2, I would like to keep OID1 and update the values from OID2 TO OID1 and delete the OID1 feature. I have a script which is partly functional that gets the count of duplicates and searches on those; but it is not deleting OID2.
import osimport sys import datetime import arcpyimport GetSRConfigimport jsonpickledef trace(): import traceback, inspect tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # script name + line number line = tbinfo.split(", ")[1] filename = inspect.getfile(inspect.currentframe()) # Get Python syntax error synerror = traceback.format_exc().splitlines()[-1] return line, filename, synerrordef GetDS(ds): d = time.clock() dt = d - ds return dtdef GetDSMsg(ds, format="%.3f s."): d = time.clock() dt = d - ds if(format==""): format = "%.3f s." return format % dtdef PrintException(): exc_type, exc_obj, tb = sys.exc_info() f = tb.tb_frame lineno = tb.tb_lineno filename = f.f_code.co_filename linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) print 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)def GetThisDir(): import inspect return os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))def GetDateTimeString(n = None): """ format a datetime to string """ if(n==None): s = time.strftime("%Y%m%d%H%M%S", time.localtime()) else: s = time.strftime("%Y%m%d%H%M%S", time.localtime()) if((isNumeric
Here's the output
C:\Python27\ArcGIS10.2\python.exe E:/C_Drive_files/Administrator/311Request/UpdateSRDB.py10/01/2015 04:08:01UPDATE_DATE_DATE > OPEN_TIME_DATEE:\C_Drive_files\Administrator\311Request\data\ServiceRequest.sde\ServiceRequest.DBO.SO_SC1COUNT_NUMBERCYLA >= 1(16739, u'1-37298161')Process finished with exit code 0
أكثر...