Created
January 30, 2014 15:22
-
-
Save p2004a/8710850 to your computer and use it in GitHub Desktop.
Gets url as argument and notify user when the website content changes
This file contains 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
#!/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