def finish(newFiles): """ Moved from Monitor class. Sends an email containing all new files. """ if(len(newFiles) > 0): text = "" subject = "Moodle Report - " for course in newFiles: text += "~"*5 + course + "~"*5 + "\n" if(len(newFiles[course]) > 0): subject += course + " " for file in newFiles[course]: if file[2]: suffix = "Changed" else: suffix = "New" text += file[0] + " - " + suffix + "\n" text += "Link: " + file[1] + "\n\n" text += "\n\n" text += "MoodleCheck.py - 1.1" subject += strftime("%d.%m.%Y") # Send the mail to every address in mails.txt mails = open("mails.txt", "r").readlines() sendmail.connectToServer() for mail in mails: mail = mail.strip() if len(mail) > 0 and not mail.startswith("#"): sendmail.sendmail(mail, subject, text) sendmail.closeConnection()
def finish(newFiles): """ Moved from Monitor class. Sends an email containing all new files. """ if (len(newFiles) > 0): text = "" subject = "Moodle Report - " for course in newFiles: text += "~" * 5 + course + "~" * 5 + "\n" if (len(newFiles[course]) > 0): subject += course + " " for file in newFiles[course]: if file[2]: suffix = "Changed" else: suffix = "New" text += file[0] + " - " + suffix + "\n" text += "Link: " + file[1] + "\n\n" text += "\n\n" text += "MoodleCheck.py - 1.1" subject += strftime("%d.%m.%Y") # Send the mail to every address in mails.txt mails = open("mails.txt", "r").readlines() sendmail.connectToServer() for mail in mails: mail = mail.strip() if len(mail) > 0 and not mail.startswith("#"): sendmail.sendmail(mail, subject, text) sendmail.closeConnection()
def checkSites(): """ Start the site checking business. """ siteFile = open("sites.txt", "r") sitesLines = siteFile.readlines() siteDict = sites.processSitesInFile(sitesLines) sitesWithDiff = {} for site in siteDict: diff = sites.checkSite(siteDict, site) if diff is not None: if len(diff.strip()) > 0: sitesWithDiff[site] = diff.strip() print "Found",len(sitesWithDiff), "Sites with diffs" # construct the email notice if len(sitesWithDiff) > 0: subject = "Observer Report - " text = "Observed Changes:\n" for site in sitesWithDiff: subject += site + ", " text += "~"*10 + " " + site + " - " + siteDict[site] text += " " + "~"*10 + "\n" text += sitesWithDiff[site] text += "\n\n" subject = subject[:-2] subject += " " + strftime("%d.%m.%Y") text += "SiteCheck.py - " + VERSION print subject print text # Send the mail to every address in mails.txt mails = open("mails.txt", "r").readlines() sendmail.connectToServer() for mail in mails: mail = mail.strip() if len(mail) > 0 and not mail.startswith("#"): sendmail.sendmail(mail, subject, text) sendmail.closeConnection()
def checkSites(): """ Start the site checking business. """ siteFile = open("sites.txt", "r") sitesLines = siteFile.readlines() siteDict = sites.processSitesInFile(sitesLines) sitesWithDiff = {} for site in siteDict: diff = sites.checkSite(siteDict, site) if diff is not None: if len(diff.strip()) > 0: sitesWithDiff[site] = diff.strip() print "Found", len(sitesWithDiff), "Sites with diffs" # construct the email notice if len(sitesWithDiff) > 0: subject = "Observer Report - " text = "Observed Changes:\n" for site in sitesWithDiff: subject += site + ", " text += "~" * 10 + " " + site + " - " + siteDict[site] text += " " + "~" * 10 + "\n" text += sitesWithDiff[site] text += "\n\n" subject = subject[:-2] subject += " " + strftime("%d.%m.%Y") text += "SiteCheck.py - " + VERSION print subject print text # Send the mail to every address in mails.txt mails = open("mails.txt", "r").readlines() sendmail.connectToServer() for mail in mails: mail = mail.strip() if len(mail) > 0 and not mail.startswith("#"): sendmail.sendmail(mail, subject, text) sendmail.closeConnection()