import arcpy import os import datetime from datetime import date, timedelta from arcpy import env env.workspace = r'G:\GISAdmin\NEW_ROADS_NOTIFICATION\Road_Exports' import smtplib import string # Scheduler. Determines the day of the week. Program only checks for new road additions on weekdays. print ("Finding current date and time...") now = datetime.datetime.now() dayofweek = datetime.datetime.now().weekday() print now if dayofweek == 0: print ("Monday") elif dayofweek == 1: print ("Tuesday") elif dayofweek == 2: print ("Wednesday") elif dayofweek == 3: print ("Thursday") elif dayofweek == 4: print ("Friday") else: print ("End: Not programmed to run on weekends.") #Export public_works.PW.Streets to shapefile and name according to the date todaysdate = str(datetime.date.today()) todaysdate = todaysdate.replace('-', '_') print todaysdate if dayofweek in [0, 1, 2, 3, 4]: arcpy.CopyFeatures_management(r'G:\Department Projects\Public Works\Public Works.sde\public_works.PW.Streets', r'G:\GISAdmin\NEW_ROADS_NOTIFICATION\Road_Exports\roads' + todaysdate + '.shp') else: print ("End: Not programmed to run on weekends (2).") #Feature compare. Compare yesterdays file with Todays new file. yesterday = str(date.today() - timedelta(1)) yesterday = yesterday.replace('-', '_') #yesterday = "2013_01_07" print yesterday todaysfile = r'G:\GISAdmin\NEW_ROADS_NOTIFICATION\Road_Exports\roads' + todaysdate + '.shp' yesterfile = r'G:\GISAdmin\NEW_ROADS_NOTIFICATION\Road_Exports\roads' + yesterday + '.shp' print todaysfile print yesterfile if arcpy.FeatureCompare_management(yesterfile, todaysfile, "FID"): print ("No changes detected in " + todaysfile + ". No further processing necessary.") else: print ("Sending email...") SUBJECT = "Steets layer changed detected" TO = "[email protected]" FROM = "[email protected]" text = "Breaking News! A change has been detected in the Public Works street spatial database." BODY = string.join(( "From: %s" % FROM, "To: %s" % TO, "Subject: %s" % SUBJECT , "", text ), "\r\n") server = smtplib.SMTP(HOST) server.sendmail(FROM, [TO], BODY) server.quit() print ("Email sent!")Solved! Go to Solution.
if arcpy.FeatureCompare_management(yesterfile, todaysfile, "FID"):
if arcpy.FeatureCompare_management(yesterfile, todaysfile, "FID"):