def send_mail(who,what): #ok we need person object but for now ok who cares log.info("With who: %s %s, doing what: %s" % (who[0],who[1],what)) log.debug("Opening message file") myfile = None try : myfile = open(config.message, "r") except IOError: log.exception("IO error in opening " % config.message) sys.exit(1) data = myfile.read() log.debug("Closing message file") myfile.close() data = data.replace("NAME", who[0] + " " + who[1]) data = data.replace("SOMETHING",what) to = [who[2]] #to = ['*****@*****.**'] # for debugging cc = config.email_cc bcc = config.email_bcc e = emailer.Email(to,cc,bcc,log) e.message(data) e.send(what + " in 30 minutes") log.info("Sent out message to %s" % to )
def main(): log.info("PROGRAM START") day = config.day_to_abv[datetime.date.today().weekday()] time = datetime.datetime.now().hour + 1 event = { 'day' : str(day), 'time' : str(time) } log.debug("Ask database for HR for day: %(day)s and time %(time)s" % event) event['loc'] = 'hr' HR = dbc.query(config.QUERY(event)) log.debug("Ask database for LL for day: %(day)s and time %(time)s" % event) event['loc'] = 'll' LL = dbc.query(config.QUERY(event)) if HR is not None: sm.send_mail(HR,"Help Room") if LL is not None: sm.send_mail(LL,"Lab Library") log.info("PROGRAM END") sys.exit(0)