From 848108934c8a1200a22d8ac8bb1d8a639376ba51 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Sat, 22 Mar 2008 10:14:52 +0100 Subject: [PATCH] urlwatch 1.1 --- ChangeLog | 14 ++++++++++++++ makefile | 4 ++-- watch.py | 28 +++++++++++++++++++++------- 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 ChangeLog diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..fa45334 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,14 @@ +2008-03-04 Thomas Perl + * Initial Version + +2008-03-17 Thomas Perl + * Release version 1.0 + +2008-03-20 Lukas Vana + * Add support for error handling missing URLs + * Notify users when NEW sites appear + * Option "display_errors" can be set in watch.py + +2008-03-22 Thomas Perl + * Release version 1.1 + diff --git a/makefile b/makefile index 4e39f23..76ffc54 100644 --- a/makefile +++ b/makefile @@ -1,8 +1,8 @@ # makefile for urlwatch PACKAGE=urlwatch -VERSION=1.0 -FILES=*.txt README *.py makefile +VERSION=1.1 +FILES=*.txt README *.py makefile ChangeLog all: true diff --git a/watch.py b/watch.py index e927295..20be456 100755 --- a/watch.py +++ b/watch.py @@ -13,6 +13,11 @@ # changes, create a "hooks.py" file that has a # filter(url, data) -> filtered_data function +# Configuration section +display_errors = False + +# Code section + import sha import sys import os.path @@ -28,11 +33,20 @@ else: for url in (x for x in open('urls.txt').read().splitlines() if not (x.startswith('#') or x.strip()=='')): filename = sha.new(url).hexdigest() - data = filter(url, urllib2.urlopen(url).read()) - if os.path.exists(filename): - old_data = open(filename).read() - diff = ''.join(difflib.unified_diff(old_data.splitlines(1), data.splitlines(1))) - if len(diff) > 0: - print '%s\nCHANGED: %s\n%s\n%s\n%s\n\n' % ('*'*60, url, '*'*60, diff, '*'*60) - open(filename, 'w').write(data) + try: + data = filter(url, urllib2.urlopen(url).read()) + if os.path.exists(filename): + old_data = open(filename).read() + diff = ''.join(difflib.unified_diff(old_data.splitlines(1), data.splitlines(1))) + if len(diff) > 0: + print '%s\nCHANGED: %s\n%s\n%s\n%s\n\n' % ('*'*60, url, '*'*60, diff, '*'*60) + else: + print '%s\nNEW: %s\n%s\n\n' % ('*'*60, url, '*'*60) + open(filename, 'w').write(data) + except urllib2.HTTPError, error: + if display_errors: + print '%s\nERROR: %s\n%s\n%s\n%s\n\n' % ('*'*60, url, '*'*60, error, '*'*60) + except urllib2.URLError, error: + if display_errors: + print '%s\nERROR: %s\n%s\n%s\n%s\n\n' % ('*'*60, url, '*'*60, error, '*'*60) -- 2.11.4.GIT