Created
November 11, 2017 18:01
-
-
Save FHRNet/2986b24f9088e05118c751f74bf3fcde to your computer and use it in GitHub Desktop.
Script to check if page has changed and send email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import urllib2 | |
| import hashlib | |
| import sendgrid | |
| # Open hash file | |
| hashfile = open('watcher.latest.txt', 'r+') | |
| hashfile.seek(0) | |
| # Retrieve page | |
| data = urllib2.urlopen('http://your/url', timeout=3).read() | |
| data_hash = hashlib.md5(data).hexdigest() | |
| if(hashfile.readline() == data_hash): | |
| # print("Up to date.") | |
| pass | |
| else: | |
| # print("Updating...") | |
| # print(data_hash) | |
| hashfile.seek(0) | |
| hashfile.write(data_hash) | |
| hashfile.truncate() | |
| # send the email here ... | |
| client = sendgrid.SendGridClient('sg_login', 'sg_pass') | |
| message = sendgrid.Mail() | |
| message.set_from('[email protected]') | |
| message.add_to('[email protected]') | |
| message.set_subject('File has changed') | |
| message.add_filter('templates', 'enable', '1') | |
| # SendGrid template id | |
| message.add_filter('templates', 'template_id', 'xxxxx') | |
| client.send(message) | |
| hashfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment