From 07ef86b677c917bc20258e389172054bb1d91dfc Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Fri, 16 May 2008 11:33:12 +0200 Subject: [PATCH] User-Agent support and Version 1.3 Add support for sending a better User-agent string to the remote host, patch by Craig Hoffman. --- ChangeLog | 6 ++++++ makefile | 2 +- watch.py | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c36e7dd..6edd3c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,3 +18,9 @@ 2008-05-10 Thomas Perl * Release version 1.2 +2008-05-15 Craig Hoffman + * Add support for sending a User-Agent header + +2008-05-16 Thomas Perl + * Release version 1.3 + diff --git a/makefile b/makefile index 6de7ff6..99bc6ba 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ # makefile for urlwatch PACKAGE=urlwatch -VERSION=1.2 +VERSION=1.3 FILES=*.txt README *.py makefile ChangeLog all: diff --git a/watch.py b/watch.py index 60a3b40..13c9391 100755 --- a/watch.py +++ b/watch.py @@ -15,6 +15,7 @@ # Configuration section display_errors = False +user_agent = 'urlwatch/1.3 (+http://thpinfo.com/2008/urlwatch/info.html)' # Code section @@ -26,6 +27,10 @@ import difflib os.chdir(os.path.dirname(os.path.abspath(sys.argv[0]))) +headers = { + 'User-agent': user_agent, +} + if os.path.exists('hooks.py'): from hooks import filter else: @@ -34,7 +39,8 @@ 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() try: - data = filter(url, urllib2.urlopen(url).read()) + request = urllib2.Request(url, None, headers) + data = filter(url, urllib2.urlopen(request).read()) if os.path.exists(filename): old_data = open(filename).read() diff = ''.join(difflib.unified_diff(old_data.splitlines(1), data.splitlines(1))) -- 2.11.4.GIT