Skip to content

Instantly share code, notes, and snippets.

@FHRNet
Created November 11, 2017 18:01
Show Gist options
  • Select an option

  • Save FHRNet/2986b24f9088e05118c751f74bf3fcde to your computer and use it in GitHub Desktop.

Select an option

Save FHRNet/2986b24f9088e05118c751f74bf3fcde to your computer and use it in GitHub Desktop.
Script to check if page has changed and send email
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