http://www.mediawiki.org/wiki/Special:Code/pywikipedia/8911
Revision: 8911 Author: russblau Date: 2011-02-03 20:10:22 +0000 (Thu, 03 Feb 2011) Log Message: ----------- Add "namespaces" option for Category.articles()
Modified Paths: -------------- branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2011-02-03 13:05:23 UTC (rev 8910) +++ branches/rewrite/pywikibot/page.py 2011-02-03 20:10:22 UTC (rev 8911) @@ -1640,10 +1640,14 @@ return
@deprecate_arg("startFrom", None) - def articles(self, recurse=False, step=None, total=None, content=False): + def articles(self, recurse=False, step=None, total=None, + namespaces=None, content=False): """ Yields all articles in the current category.
+ By default, yields all *pages* in the category that are not + subcategories! + @param recurse: if not False or 0, also iterate articles in subcategories. If an int, limit recursion to this number of levels. (Example: recurse=1 will iterate articles in first-level @@ -1652,12 +1656,15 @@ @param step: limit each API call to this number of pages @param total: iterate no more than this number of pages in total (at all levels) + @param namespaces: only yield pages in the specified namespaces + @type namespace: int or list of ints @param content: if True, retrieve the content of the current version of each page (default False)
""" - namespaces = [x for x in self.site.namespaces() - if x>=0 and x!=14] + if namespaces is None: + namespaces = [x for x in self.site.namespaces() + if x>=0 and x!=14] for member in self.site.categorymembers(self, namespaces=namespaces, step=step, total=total,