Revision: 4091 Author: cosoleto Date: 2007-08-22 21:52:43 +0000 (Wed, 22 Aug 2007)
Log Message: ----------- Patch to disable search engine/sleep/stop/ignore if search engine refuse your query because you exceed daily quota.
Modified Paths: -------------- trunk/pywikipedia/config.py trunk/pywikipedia/copyright.py
Modified: trunk/pywikipedia/config.py =================================================================== --- trunk/pywikipedia/config.py 2007-08-22 20:52:26 UTC (rev 4090) +++ trunk/pywikipedia/config.py 2007-08-22 21:52:43 UTC (rev 4091) @@ -288,10 +288,10 @@
############## SEARCH ENGINE SETTINGS ##############
-# Some scripts allow querying Google via the Google Web API. To use this feature, you must -# install the pyGoogle module from http://pygoogle.sf.net/ and have a Google -# Web API license key. Note that -# Google doesn't give out license keys anymore. +# Some scripts allow querying Google via the Google Web API. To use this feature, +# you must install the pyGoogle module from http://pygoogle.sf.net/ and have a +# Google Web API license key. Note that Google doesn't give out license keys +# anymore. google_key = ''
# Some scripts allow using the Yahoo! Search Web Services. To use this feature, @@ -326,6 +326,18 @@ # Number of attempts on connection error. copyright_connection_tries = 10
+# Behavior if an exceeded error occur. +# +# Possibilities: +# +# 0 = None +# 1 = Disable search engine +# 2 = Sleep (default) +# 3 = Stop + +copyright_exceeded_in_queries = 2 +copyright_exceeded_in_queries_sleep_hours = 6 + # Append last modified date of URL to script result copyright_show_date = True
Modified: trunk/pywikipedia/copyright.py =================================================================== --- trunk/pywikipedia/copyright.py 2007-08-22 20:52:26 UTC (rev 4090) +++ trunk/pywikipedia/copyright.py 2007-08-22 21:52:43 UTC (rev 4091) @@ -659,6 +659,20 @@ url.append((add_item, engine, comment)) return
+def exceeded_in_queries(engine): + """Behavior if an exceeded error occur.""" + + # Disable search engine + if config.copyright_exceeded_in_queries == 1: + exec('config.copyright_' + engine + ' = False') + # Sleeping + if config.copyright_exceeded_in_queries == 2: + print "Got a queries exceeded error. Sleeping for %d hours..." % (config.copyright_exceeded_in_queries_sleep_hours) + time.sleep(config.copyright_exceeded_in_queries_sleep_hours * 60 * 60) + # Stop execution + if config.copyright_exceeded_in_queries == 3: + raise 'Got a queries exceeded error.' + def get_results(query, numresults = 10): url = list() query = re.sub("[()"<>]", "", query) @@ -677,9 +691,13 @@ except KeyboardInterrupt: raise except Exception, err: - #SOAP.faultType: <Fault SOAP-ENV:Server: Exception from service object: - # Daily limit of 1000 queries exceeded for key xxx> print "Got an error ->", err + # + # SOAP.faultType: <Fault SOAP-ENV:Server: Exception from service object: + # Daily limit of 1000 queries exceeded for key ***> + # + if 'Daily limit' in str(err): + exceeded_in_queries('google') if search_request_retry: search_request_retry -= 1 if config.copyright_yahoo: @@ -696,6 +714,8 @@ search_request_retry = 0 except Exception, err: print "Got an error ->", err + if 'limit exceeded' in str(err): + exceeded_in_queries('yahoo') if search_request_retry: search_request_retry -= 1 if config.copyright_msn:
pywikipedia-l@lists.wikimedia.org