Revision: 7098
Author: purodha
Date: 2009-07-26 23:13:57 +0000 (Sun, 26 Jul 2009)
Log Message:
-----------
Add -redirectonly page generator.
Modified Paths:
--------------
trunk/pywikipedia/pagegenerators.py
Modified: trunk/pywikipedia/pagegenerators.py
===================================================================
--- trunk/pywikipedia/pagegenerators.py 2009-07-26 14:18:13 UTC (rev 7097)
+++ trunk/pywikipedia/pagegenerators.py 2009-07-26 23:13:57 UTC (rev 7098)
@@ -137,6 +137,15 @@
-recentchanges Work on new and edited pages returned by [[Special:Recentchanges]].
Can also be given as "-recentchanges:n" where n is the number
of pages to be returned, else 100 pages are returned.
+
+-redirectonly Work on redirect pages only, not their target pages.
+ The robot goes alphabetically through all redirect pages
+ on the wiki, starting at the named page. The
+ argument can also be given as "-redirectonly:pagetitle".
+
+ You can also include a namespace. For example,
+ "-redirectonly:Template:!" will make the bot work on
+ all redirect pages in the template namespace.
"""
@@ -1058,6 +1067,16 @@
firstPageTitle).titleWithoutNamespace()
gen = AllpagesPageGenerator(firstPageTitle, namespace,
includeredirects=False)
+ elif arg.startswith('-redirectonly'):
+ firstPageTitle = arg[15:]
+ if not firstPageTitle:
+ firstPageTitle = wikipedia.input(
+ u'At which page do you want to start?')
+ namespace = wikipedia.Page(site, firstPageTitle).namespace()
+ firstPageTitle = wikipedia.Page(site,
+ firstPageTitle).titleWithoutNamespace()
+ gen = AllpagesPageGenerator(firstPageTitle, namespace,
+ includeredirects='only')
elif arg.startswith('-prefixindex'):
prefix = arg[13:]
namespace = None
Revision: 7093
Author: alexsh
Date: 2009-07-25 09:39:25 +0000 (Sat, 25 Jul 2009)
Log Message:
-----------
site().solveCaptcha():Add API Captcha solution accroding MW ConfirmEdit extension API details.
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2009-07-25 08:38:23 UTC (rev 7092)
+++ trunk/pywikipedia/wikipedia.py 2009-07-25 09:39:25 UTC (rev 7093)
@@ -4599,24 +4599,38 @@
return '&'.join(l)
def solveCaptcha(self, data):
- captchaW = re.compile('<label for="wpCaptchaWord">(?P<question>[^<]*)</label>')
- captchaR = re.compile('<input type="hidden" name="wpCaptchaId" id="wpCaptchaId" value="(?P<id>\d+)" />')
- match = captchaR.search(data)
- if match:
- id = match.group('id')
- match = captchaW.search(data)
+ if type(data) == dict: # API Mode result
+ if data['result'].has_key("captcha"):
+ type = data['result']['captcha']['type']
+ id = data['result']['captcha']['id']
+ if type in ['simple', 'math', 'question']:
+ answer = input('What is the answer to the captcha "%s" ?' % data['result']['captcha']['question'])
+ elif type == 'image':
+ url = self.protocol() + '://' + self.hostname() + self.captcha_image_address(id)
+ answer = ui.askForCaptcha(url)
+ else: #no captcha id result, maybe ReCaptcha.
+ raise CaptchaError('We have been prompted for a ReCaptcha, but pywikipedia does not yet support ReCaptchas')
+ return {'id':id, 'answer':answer}
+ return None
+ else:
+ captchaW = re.compile('<label for="wpCaptchaWord">(?P<question>[^<]*)</label>')
+ captchaR = re.compile('<input type="hidden" name="wpCaptchaId" id="wpCaptchaId" value="(?P<id>\d+)" />')
+ match = captchaR.search(data)
if match:
- answer = input('What is the answer to the captcha "%s" ?' % match.group('question'))
- else:
- if not config.solve_captcha:
- raise CaptchaError(id)
- url = self.protocol() + '://' + self.hostname() + self.captcha_image_address(id)
- answer = ui.askForCaptcha(url)
- return {'id':id, 'answer':answer}
- Recaptcha = re.compile('<script type="text/javascript" src="http://api\.recaptcha\.net/[^"]*"></script>')
- if Recaptcha.search(data):
- raise CaptchaError('We have been prompted for a ReCaptcha, but pywikipedia does not yet support ReCaptchas')
- return None
+ id = match.group('id')
+ match = captchaW.search(data)
+ if match:
+ answer = input('What is the answer to the captcha "%s" ?' % match.group('question'))
+ else:
+ if not config.solve_captcha:
+ raise CaptchaError(id)
+ url = self.protocol() + '://' + self.hostname() + self.captcha_image_address(id)
+ answer = ui.askForCaptcha(url)
+ return {'id':id, 'answer':answer}
+ Recaptcha = re.compile('<script type="text/javascript" src="http://api\.recaptcha\.net/[^"]*"></script>')
+ if Recaptcha.search(data):
+ raise CaptchaError('We have been prompted for a ReCaptcha, but pywikipedia does not yet support ReCaptchas')
+ return None
def postForm(self, address, predata, sysop=False, cookies = None):
"""Post http form data to the given address at this site.