print ' - Error sending emails: {0}'.format(e.message) sys.exit(1) print ' - {0} emails sent in {1:0.2f} seconds.'.format(sentemails, totaltime) if sentemails != len(emails): currdate = datetime.date.today().strftime('%Y%m%d') errfile = 'email_errors_{0}.txt'.format(currdate) print ' - errors encountered sending some emails.' with open(errfile, 'w') as f: f.writelines([x+'\n' for x in postman.mailerrors]) print ' - error details saved to {0}'.format(errfile) else: print ' - No notices to send.' #Now, delete the sqlite database, unless the --keep option has been passed. localdb.close_db() del localdb if args.keep: #Do nothing to the DB; we'll need it for a later mailing. print 'Keeping scratch db for later use...' elif args.rename: #Rename and keep the DB, we want it for checking and testing later. print 'Keeping scratch db for posterity...' currdate = datetime.date.today().strftime('%Y%m%d') try: mailer.keep_db(dbname, currdate) except mailer.MailError as e: print ' - Error renaming scratch DB: {0}'.format(e.message) sys.exit(1) else: print 'Deleting scratch db...'
notice['namefield'], notice['addrfield'], notice['uidfield'] ] exportfields = [ cfg['namefield'], cfg['addrfield'], cfg['uidfield'] ] joinedrows = spatial.extract_results(joined, fcfields, exportfields) if len(joinedrows) > 0: localdb.save_points(cfg['mailtable'], joinedrows, notice['table'], cfg['sourcefield']) totaljoined += len(joinedrows) print ' - {0} rows saved for notice {1}'.format( len(joinedrows), notice['table']) else: print ' - {0} rows saved for notice {1}'.format(0, notice['table']) localdb.close_db() #Now, delete the temp GDB, unless the --keep option has been passed. if args.rename: print 'Keeping scratch GDB for posterity...' currdate = datetime.date.today().strftime('%Y%m%d') try: spatial.keep_gdb(gdb, currdate) except spatial.ArcError as e: print ' - Error renaming spatial DB: {0}'.format(e.message) sys.exit(1) else: print 'Deleting scratch GDB...' try: spatial.del_gdb(gdb) except spatial.ArcError as e: