from DateTime import DateTime for r in context.portal_catalog(): date1 = expires #the expiration date date2 = context.ZopeTime() #the current date t = int(date1.earliestTime()-date2.earliestTime()) #the integer difference between dates x = r.getObjec() #gets object via catalog if t==XX: #if there is XX days between dates... contentObject = r.getObject() objectHistory=contentObject.portal_workflow.getInfoFor(contentObject, 'review_history') thisRevision=objectHistory[-1] nowDate=thisRevision['time'].aCommon() authorComment=thisRevision['comments'] mailList=[] try: mailhost=getattr(context, context.portal_url.superValues('Mail Host')[0].id) except: raise AttributeError, "Cannot find a Mail Host object" mMsg = 'An item you created on the website is nearing expiry.\n\nPlease update the item.\n\nThis email was generated and sent by the website.\n\n' mMsg += 'Title: ' + contentObject.TitleOrId() + '\n\n' mMsg += 'Description: ' + contentObject.Description() + '\n\n' mMsg += contentObject.absolute_url() + '\n' mMsg += 'Author comment:' + authorComment + '\n\n' mTo = context.portal_membership.getMemberById(contentObject.Creator()).email mFrom = 'Webmaster@acme.com' mSubj = 'Website item nearing expiration date' mailhost.send(mMsg, mTo, mFrom, mSubj) #send email to author elif t==0: #else if expiration date=today's date if x.review_state!="private": #change review_state to private via expire transaction try: context.portal_workflow.doActionFor(contentObject,'expire') except: print 'didnt change state' return printed