-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckupdate.py
More file actions
executable file
·29 lines (23 loc) · 1.01 KB
/
checkupdate.py
File metadata and controls
executable file
·29 lines (23 loc) · 1.01 KB
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
#!/usr/bin/python
import urllib
import smtplib
import shelve
import logging
dbpath = '/home/ypcat/cgi-bin/notify.db'
logpath = '/home/ypcat/cgi-bin/checkupdate.log'
sender = 'ypcat@eumacro.csie.org'
db = shelve.open(dbpath, writeback=True)
logging.basicConfig(filename=logpath, level=logging.DEBUG, format='%(asctime)s %(message)s', datefmt='%c')
for name, site in db['sites'].items():
r = urllib.urlopen(site['url'])
if 'etag' not in site or not site['etag']:
site['etag'] = r.headers['etag']
logging.info('init %s with etag %s' % (name, site['etag']))
elif site['etag'] != r.headers['etag']:
site['etag'] = r.headers['etag']
smtplib.SMTP('localhost').sendmail(sender, site['subscribers'].keys(), 'Subject: %s updated\n\nvisit %s' % (name, site['url']))
logging.info('%s updated with etag %s' % (name, site['etag']))
logging.info('sent notification to %s' % ', '.join(site['subscribers'].keys()))
else:
logging.info('%s unmodified' % name)
db.close()