Skip to content

Instantly share code, notes, and snippets.

@p2004a
Created January 30, 2014 15:22
Show Gist options
  • Save p2004a/8710850 to your computer and use it in GitHub Desktop.
Save p2004a/8710850 to your computer and use it in GitHub Desktop.
Gets url as argument and notify user when the website content changes
#!/usr/bin/python
import sys, time, re, urllib2, hashlib, pynotify
def get_site_hash(url):
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36')]
u = opener.open(url)
data = u.read()
return hashlib.sha256(data).hexdigest()
def send_notify(str):
pynotify.Notification("Site Changes Monitor", str, "dialog-information").show()
def main(args):
if len(args) == 1: return
pynotify.init("Site Changes Monitor")
url = args[1]
site_hash = get_site_hash(url)
while True:
new_site_hash = get_site_hash(url)
if site_hash != new_site_hash:
send_notify("site changed")
site_hash = new_site_hash
time.sleep(5)
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment