[Pywikipedia-l] SVN: [5342] branches/rewrite/pywikibot/site.py
nicdumz at svn.wikimedia.org
nicdumz at svn.wikimedia.org
Fri May 9 11:35:15 UTC 2008
Revision: 5342
Author: nicdumz
Date: 2008-05-09 11:35:15 +0000 (Fri, 09 May 2008)
Log Message:
-----------
* Adding a batch parameter to categorymembers to set the numbers of pages retrieved at once
* Trying to address NoPage issues
Modified Paths:
--------------
branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2008-05-09 10:56:35 UTC (rev 5341)
+++ branches/rewrite/pywikibot/site.py 2008-05-09 11:35:15 UTC (rev 5342)
@@ -744,7 +744,7 @@
for ns in namespaces)
return tlgen
- def categorymembers(self, category, namespaces=None):
+ def categorymembers(self, category, namespaces=None, batch=None):
"""Iterate members of specified category.
@param category: The Category to iterate.
@@ -754,6 +754,8 @@
however, that the iterated values are always Page objects, even
if in the Category or Image namespace.
@type namespaces: list of ints
+ @param batch: the number of pages to fetch each time.
+ @type batch: int
"""
if category.namespace() != 14:
@@ -766,6 +768,11 @@
if namespaces is not None:
cmgen.request[u"gcmnamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ if batch is not None:
+ if batch > 5000:
+ logging.debug("No more than 5000 rows can be fetched at once.")
+ batch=5000
+ cmgen.request[u'cmlimit'] = str(batch)
return cmgen
def loadrevisions(self, page=None, getText=False, revids=None,
@@ -881,6 +888,8 @@
raise Error(
u"loadrevisions: Query on %s returned data on '%s'"
% (page, pagedata['title']))
+ if pagedata.has_key('missing'):
+ raise NoPage(u'Page %s does not exist' % page.title(asLink=True))
else:
page = Page(self, pagedata['title'])
api.update_page(page, pagedata)
More information about the Pywikipedia-l
mailing list