Created
July 24, 2011 20:25
-
-
Save jotbe/1103063 to your computer and use it in GitHub Desktop.
Check for remote file 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/env python | |
"""This script checks the Last-Modified header of a remote file. | |
It will use Growl to notify the user, when the field differs from a specified comparison time. | |
""" | |
__author__ = 'Jan Beilicke' | |
__date__ = '2011-07-24' | |
import sys | |
import httplib | |
import urllib2 | |
import Growl | |
if __name__ == '__main__': | |
filename = 'lightning.xpi' | |
check_uri = 'http://ftp.mozilla.org/pub/mozilla.org/calendar/lightning/nightly/latest-comm-miramar/macosx-xpi/%s' % filename | |
compare_to = 'Sat, 02 Jul 2011 09:57:09 GMT' | |
print 'Checking URL: %s' % check_uri | |
growl_appname = 'Check remote file' | |
growl_notifications = ['Updated', 'Error'] | |
growl = Growl.GrowlNotifier(growl_appname, growl_notifications) | |
growl.register() | |
request = urllib2.Request(check_uri) | |
opener = urllib2.build_opener() | |
try: | |
request.add_header('If-Modified-Since', compare_to) | |
data = opener.open(request) | |
except urllib2.HTTPError, e: | |
print('%s - %s' % (e.msg, e.code)) | |
sys.exit() | |
except urllib2.URLError, e: | |
print(e.reason) | |
growl.notify('Error', 'Moz-Update-Check', str(e.reason), sticky=True) | |
sys.exit() | |
print('File has been updated!') | |
growl.notify('Updated', 'Moz-Update-Check', '%s has been updated!' % filename, sticky=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment