Revision: 5983 Author: filnik Date: 2008-10-16 16:49:37 +0000 (Thu, 16 Oct 2008)
Log Message: ----------- New function: pageAPInfo() to know if a page is a redirect or it's empty calling the API to improve the performance in some situations
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2008-10-16 16:49:27 UTC (rev 5982) +++ trunk/pywikipedia/wikipedia.py 2008-10-16 16:49:37 UTC (rev 5983) @@ -885,6 +885,33 @@ return False return True
+ def pageAPInfo(self): + """Return True if page exists on the wiki, + Raise IsRedirectPage if it's a redirect + Raise NoPage if the page doesn't exist + + Using the API should be a lot faster. + Function done in order to improve the scripts performance. + + """ + params = { + 'action' :'query', + 'prop' :'info', + 'titles' :self.title(), + } + data = query.GetData(params, + useAPI = True, encodeTitle = False) + pageid = data['query']['pages'].keys()[0] + if data['query']['pages'][pageid].keys()[0] == 'lastrevid': + return True + elif data['query']['pages'][pageid].keys()[0] == 'redirect': + raise IsRedirectPage + else: + # should not exists, OR we have problems. + # better double check in this situations + x = self.get() + return True # if we reach this point, we had no problems. + def isRedirectPage(self): """Return True if this is a redirect, False if not or not existing.""" try:
pywikipedia-l@lists.wikimedia.org