AnsweredAssumed Answered

Loop through List find Records with no entries in last 30 days

Question asked by jay.kapalczynski on May 4, 2017
Latest reply on May 5, 2017 by jay.kapalczynski

I have  list that contains all the Boat Ramps I want to validate.

I want a query that loops through each boat ramp name and then determines which ones do not have a record in the last 30 days.  I need that result to be written to a CSV file.

 

I think I have the beginning and the end but not the part that loops and queries for Boat Ramps that do NOT have a record in the last 30 days

 

I need to query the FC variable (my dataset that has all the records)

"Ramp_1" is the field in the FC that has the Boat Ramp Name

Using the List for Boat Ramp names (List) 

 

Loop through the List and find which records in the FC do not have a record in the last 30 days.

 

 

import arcpy
import os, string
import smtplib, shutil
import email, time
import sys, csv
from email.MIMEMultipart import MIMEMultipart
from email.mime.text import MIMEText


#Variables==============================================

arcpy.env.workspace = "C:\\Users\\xxxx\\AppData\\Roaming\ESRI\\Desktop10.4\\ArcCatalog\\xxxx.sde"
fc = "xxxxx"

var_additionalcomments = 'additionalcomments'
var_CreationDate,var_Creator = 'CreationDate','Creator'

headers = ['comments','Creation Date','Creator']
        
QueryFields = [var_additionalcomments,var_CreationDate,var_Creator


# Get Date 30 days ago
import datetime as DT
today = DT.date.today()
month_ago = today - DT.timedelta(days=30)
print month_ago

# Get list of all Boat Ramps
myLayer = "BoatRampsWGS"
myField = "SITENAME"
myBoatRampList = [row[0] for row in arcpy.da.SearchCursor(myLayer, myField)]
print myBoatRampList

# Loop through List of Boat Ramps and return those that dont have inspection within 30 days

# I AM LOST HERE .... THIS IS WHERE THE LOOP AND QUERY SHOULD BE BUT DONT KNOW WHERE TO STATR




# Write the results to CSV file.
outFileRegionDate = open(r"E:\ArcGISProjects\xxxx\PythonScripts\PythonSync\PythonScripts\z_outFileRegionDate.csv", "w") 

mylist=[]
with arcpy.da.SearchCursor(fc, QueryFields, where_clause=expressionDate) as cursorDate:
    outFileRegionDate.write(','.join(headers) + '\n')
    flagDate = False          
    for row in cursorDate:
        flagDate = True
        zvalDate = str('{0},{1},{2}'.format(row[0],row[1],row[2]))
        outFileRegionDate.write(zvalDate + "%s\n")
        mylist.append(zvalDate)
    if not flagDate:
        print "No rows found"
outFileRegionDate.close()

Outcomes