Revision: 6748 Author: multichill Date: 2009-04-29 11:54:39 +0000 (Wed, 29 Apr 2009)
Log Message: ----------- Sometimes the bot gets stuck at a certain image. Limit the number of tries to 10 so the bot won't get stuck forever at one image.
Modified Paths: -------------- trunk/pywikipedia/imagerecat.py
Modified: trunk/pywikipedia/imagerecat.py =================================================================== --- trunk/pywikipedia/imagerecat.py 2009-04-28 06:58:57 UTC (rev 6747) +++ trunk/pywikipedia/imagerecat.py 2009-04-29 11:54:39 UTC (rev 6748) @@ -110,19 +110,25 @@ parameters = urllib.urlencode({'i' : imagepage.titleWithoutNamespace().encode('utf-8'), 'r' : 'on', 'go-clean' : 'Find+Categories', 'p' : search_wikis, 'cl' : hint_wiki}) commonsenseRe = re.compile('^#COMMONSENSE(.*)#USAGE(\s)+((?P<usagenum>(\d)+))\s(?P<usage>(.*))\s#KEYWORDS(\s)+((?P<keywords>(\d)+))(.*)#CATEGORIES(\s)+((?P<catnum>(\d)+))\s(?P<cats>(.*))\s#GALLERIES(\s)+((?P<galnum>(\d)+))\s(?P<gals>(.*))\s(.*)#EOF$', re.MULTILINE + re.DOTALL)
- gotInfo = False; - + gotInfo = False + maxtries = 10 + tries = 0 + while(not gotInfo): try: - commonsHelperPage = urllib.urlopen("http://toolserver.org/~daniel/WikiSense/CommonSense.php?%s" % parameters) - matches = commonsenseRe.search(commonsHelperPage.read().decode('utf-8')) - gotInfo = True + if ( tries < maxtries ): + tries = tries + 1 + commonsHelperPage = urllib.urlopen("http://toolserver.org/~daniel/WikiSense/CommonSense.php?%s" % parameters) + matches = commonsenseRe.search(commonsHelperPage.read().decode('utf-8')) + gotInfo = True + else: + break except IOError: wikipedia.output(u'Got an IOError, let's try again') except socket.timeout: wikipedia.output(u'Got a timeout, let's try again')
- if matches: + if (matches and gotInfo): if(matches.group('usagenum') > 0): used = matches.group('usage').splitlines() for use in used:
pywikipedia-svn@lists.wikimedia.org