-
Notifications
You must be signed in to change notification settings - Fork 3
/
SiteCheck.py
65 lines (50 loc) · 1.62 KB
/
SiteCheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'''
Checks a list of urls for changes.
See README for more information.
'''
import sys
from time import strftime
import sendmail
import sites
VERSION = "1.3"
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()
if __name__ == "__main__":
try:
sys.exit(checkSites())
except Exception as err:
print err # Stupid but gets the job done...
sys.exit(1)