All of the code is below. Thank you.
# Import system modules
import sys, string, os, datetime, calendar
import arcpy
# Get start time
startTime = str(datetime.datetime.now())
today = datetime.date.today()
month = today.strftime('%m')
print month
# Get previous month for old Civic Address feature class naming
prev_month = int(month) - 1
if prev_month == 0:
prev_month = 12
print prev_month
prev_month_2 = int(month)-2
if prev_month_2 == 0:
prev_month_2=12
mon2 = calendar.month_name[prev_month_2]
mon = calendar.month_name[prev_month]
print mon
print mon2
# Input File
inFolder = r"path\\updateCADB"
outLocation = r"Database Connections\un@test.sde"
# Local variables...
db = outLocation
dl = inFolder
Civic_Addresses = db + "\\Civic_Addresses"
arcpy.AddMessage(startTime)
print inFolder
print outLocation
print db
print dl
try:
# Process: Remove Domain From Field...
if arcpy.Exists(db + "\\Civic_Addresses"):
arcpy.RemoveDomainFromField_management(db + "\\Civic_Addresses", "COUNTY_CD", "")
arcpy.RemoveDomainFromField_management(db + "\\Civic_Addresses", "PLN_CD", "")
arcpy.RemoveDomainFromField_management(db + "\\Civic_Addresses", "COORDINATE_CLASS_CD", "")
arcpy.RemoveDomainFromField_management(db + "\\Civic_Addresses", "COORDINATE_METHOD_CD", "")
arcpy.RemoveDomainFromField_management(db + "\\Civic_Addresses", "COORDINATE_SOURCE_CD", "")
arcpy.RemoveDomainFromField_management(db + "\\Civic_Addresses", "ST_TYPE_CD", "")
arcpy.AddMessage("Step 1: Domains removed from fields")
print "domains removed from fields"
# Process: Delete Domain...
desc = arcpy.Describe(db)
print desc
domains = desc.Domains
print domains
for domain in domains:
print domain
if (domain=="County"):
arcpy.DeleteDomain_management(db, "County")
print "County Domain Deleted"
elif (domain=="Places"):
arcpy.DeleteDomain_management(db, "Places")
print "Places Domain Deleted"
elif (domain=="Coord_Classes"):
arcpy.DeleteDomain_management(db, "Coord_Classes")
print "Coord Classes Domain Deleted"
elif (domain=="Coord_Methods"):
arcpy.DeleteDomain_management(db, "Coord_Methods")
print "Coord Methods Domain Deleted"
elif (domain=="Coord_Sources"):
arcpy.DeleteDomain_management(db, "Coord_Sources")
print "Coord Sources Domain Deleted"
elif (domain=="Street_Dir"):
arcpy.DeleteDomain_management(db, "Street_Dir")
print "Street Dir Domain Deleted"
elif (domain=="Street_Types"):
arcpy.DeleteDomain_management(db, "Street_Types")
print "Street Types Domain Deleted"
elif (domain=="Unit_Types"):
arcpy.DeleteDomain_management(db, "Unit_Types")
print "Unit Types Domain Deleted"
arcpy.AddMessage("Step 2: Domains deleted")
print "table to domains starting"
# Process: Table To Domain...
arcpy.TableToDomain_management(inFolder + "\\counties.txt", "CD", "NAME",db, "County", "Individual County Names", "APPEND")
arcpy.TableToDomain_management(inFolder + "\\place_names.txt", "CD", "NAME_E", db, "Places", "Place Names", "APPEND")
arcpy.TableToDomain_management(inFolder + "\\coordinate_classes.txt", "CD", "NAME_E", db, "Coord_Classes", "Coordinate Classes", "APPEND")
arcpy.TableToDomain_management(inFolder + "\\coordinate_methods.txt", "CD", "NAME_E", db, "Coord_Methods", "Coordinate Methods", "APPEND")
arcpy.TableToDomain_management(inFolder + "\\coordinate_sources.txt", "CD", "NAME_E", db, "Coord_Sources", "Coordinate Sources", "APPEND")
arcpy.TableToDomain_management(inFolder + "\\street_directions.txt", "CD", "NAME_E", db, "Street_Dir", "Street Directions", "APPEND")
arcpy.TableToDomain_management(inFolder + "\\street_types.txt", "CD", "NAME", db, "Street_Types", "Street Types", "APPEND")
arcpy.TableToDomain_management(inFolder + "\\unit_types.txt", "CD", "NAME_E", db, "Unit_Types", "Unit Types", "APPEND")
print "Table to domains complete"
arcpy.AddMessage("Step 3: New Domains Created")
# Process: Feature Class to Feature Class...
if arcpy.Exists(db + "\\Civic_Addresses_" + mon2):
arcpy.Delete_management(db + "\\Civic_Addresses_" + mon2)
if arcpy.Exists(db + "\\Civic_Addresses"):
## changed the next line
arcpy.Rename_management(Civic_Addresses, "Civic_Addresses_" + mon)
print "renaming of civic address feature class complete"
arcpy.AddMessage("Step 4: Last Months Civic Addresses Backed Up")
# Make XY Event Layer...
arcpy.MakeXYEventLayer_management(inFolder + "\\locations.txt", "X_COORDINATE", "Y_COORDINATE", "locations_Layer", "PROJCS['NAD_1983_CSRS_New_Brunswick_Stereographic',GEOGCS['GCS_North_American_1983_CSRS',DATUM['D_North_American_1983_CSRS',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Double_Stereographic'],PARAMETER['False_Easting',2500000.0],PARAMETER['False_Northing',7500000.0],PARAMETER['Central_Meridian',-66.5],PARAMETER['Scale_Factor',0.999912],PARAMETER['Latitude_Of_Origin',46.5],UNIT['Meter',1.0]];-28216700 -23260100 10000;#;#;0.001;#;#;IsHighPrecision")
print "make xy event layer completed"
arcpy.AddMessage(" make XY event layer completed")
# Process: Copy Features...
arcpy.CopyFeatures_management("locations_Layer", db + "\\Civic_Addresses")
print "Civic Addresses updated"
arcpy.AddMessage("Step 5: New Civic Addresses Loaded Successfully")
# Update ST_TYPE_CD NULL fields with 999
print "Step 6 is getting started"
cur = arcpy.UpdateCursor(db + "\\Civic_Addresses","ST_TYPE_CD IS NULL")
row = cur.next()
while row:
row.ST_TYPE_CD = 999
cur.UpdateRow(row)
row = cur.next()
del row
del cur
print "Street Types with NULLS defined"
arcpy.AddMessage("Step 6: After del cur")
# Process: Assign Domain To Field...
arcpy.AssignDomainToField_management(Civic_Addresses, "COUNTY_CD", "County", "")
arcpy.AssignDomainToField_management(Civic_Addresses, "PLN_CD", "Places", "")
arcpy.AssignDomainToField_management(Civic_Addresses, "COORDINATE_CLASS_CD", "Coord_Classes", "")
arcpy.AssignDomainToField_management(Civic_Addresses, "COORDINATE_METHOD_CD", "Coord_Methods", "")
arcpy.AssignDomainToField_management(Civic_Addresses, "COORDINATE_SOURCE_CD", "Coord_Sources", "")
arcpy.AssignDomainToField_management(Civic_Addresses, "ST_TYPE_CD", "Street_Types", "")
## Street Direction Codes are not assigned to any of the civic address records
# arcpy.AssignDomainToField_management(Civic_Addresses, "STREET_DIR_CD", "Street_Dir", "")
## Unit Type Codes are not assigned to any of the civic address records
#arcpy.AssignDomainToField_management(Civic_Addresses, "UNIT_TYPE_CD", "Unit_Types", "")
arcpy.AddMessage("Step 6: Civic Address Update is Complete")
print startTime
endTime = str(datetime.datetime.now())
print endTime
## email saying process succeeded
except:
error = arcpy.GetMessages()
arcpy.AddError(error)
print "Process Failed"
## email saying process failed