From 5f27fea8fc3b7b07ac2d5e486dd0bb2f9ff1fcd6 Mon Sep 17 00:00:00 2001 From: urlbot Date: Fri, 21 Aug 2015 23:35:28 +0200 Subject: [PATCH] using global uniq USER_AGENT --- common.py | 3 ++- plugins.py | 2 +- urlbot.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common.py b/common.py index 916dbbb..0952f2f 100644 --- a/common.py +++ b/common.py @@ -15,7 +15,8 @@ RATE_CHAT = 0x08 RATE_URL = 0x10 BUFSIZ = 8192 -delay = 0.100 # seconds +EVENTLOOP_DELAY = 0.100 # seconds +USER_AGENT = '''Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.0''' basedir = '.' if 2 == len(sys.argv): diff --git a/plugins.py b/plugins.py index a1c9ae5..5915c5a 100644 --- a/plugins.py +++ b/plugins.py @@ -881,7 +881,7 @@ def command_dsa_watcher(argv, **args): try: request = urllib.request.Request(url) - request.add_header('User-Agent', '''Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.0''') + request.add_header('User-Agent', USER_AGENT) response = urllib.request.urlopen(request) html_text = response.read(BUFSIZ) # ignore more than BUFSIZ except Exception as e: diff --git a/urlbot.py b/urlbot.py index e826bb6..d5cfca5 100755 --- a/urlbot.py +++ b/urlbot.py @@ -33,7 +33,7 @@ def fetch_page(url): log.info('fetching page ' + url) try: request = urllib.request.Request(url) - request.add_header('User-Agent', '''Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.0''') + request.add_header('User-Agent', USER_AGENT) response = urllib.request.urlopen(request) html_text = response.read(BUFSIZ) # ignore more than BUFSIZ response.close() @@ -379,7 +379,7 @@ if '__main__' == __name__: xmpp.disconnect() sys.exit(1) - time.sleep(delay) + time.sleep(EVENTLOOP_DELAY) except KeyboardInterrupt: print('') exit(130)