Last active
November 13, 2019 22:05
-
-
Save seaukara/7674c99afa29e50b1144ffa9aab48497 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------- | |
# Name: Update Master Table | |
# Purpose: Ensures that the master and new table are identical(matching the new table) | |
# | |
# Author: kara | |
#------------------------------------------------------------------------------- | |
import arcpy | |
mastertable = r"" | |
newtable = r"" | |
mastervalues = [] | |
newvalues = [] | |
with arcpy.da.SearchCursor(newtable, "*") as newCursor: # create a search cursor for the new table | |
for new in newCursor: | |
newvalues.append(new[1]) # append all values in the new table to a list | |
with arcpy.da.UpdateCursor(mastertable, "*") as MasterCursor: # create an update cursor for the master table | |
for master in MasterCursor: | |
mastervalues.append(master[1]) # append all values in the master table to a list | |
if new[1] == master[1]: # determnes if the ID found in the new table is in the master table, procedes if true | |
master[2] = new[2] | |
#master[3] = new[3] | |
MasterCursor.updateRow(master) # updates the records as necessary | |
for master in MasterCursor: # removes any records in the master table not found in the new table | |
if master[1] not in newvalues: | |
MasterCursor.deleteRow() | |
del newCursor | |
with arcpy.da.SearchCursor(newtable, "*") as newCursor: | |
for new in newCursor: # adds any records to the master table found in the new table not in the master table | |
if new[1] not in mastervalues: | |
with arcpy.da.InsertCursor(mastertable, "ID") as updateMaster: | |
updateMaster.insertRow(new[3]) | |
print ("Complete") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment