Add filter options to redfam.article_generator
To give the posibility to filter not existing pages or redirect pages or vice versa. Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=87 FS#87]
This commit is contained in:
@@ -458,14 +458,41 @@ class RedFamWorker( RedFam ):
|
||||
# with wrong month abreviations in strptime
|
||||
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
|
||||
|
||||
def article_generator(self):
|
||||
def article_generator(self, filter_existing=None, filter_redirects=None ):
|
||||
"""
|
||||
Yields pywikibot pageobjects for articles belonging to this redfams
|
||||
in a generator
|
||||
self.
|
||||
|
||||
@param filter_existing Set to True to only get existing pages
|
||||
set to False to only get nonexisting pages
|
||||
unset/None results in not filtering
|
||||
@type filter_existing bool/None
|
||||
@param filter_redirects Set to True to get only noredirectpages,
|
||||
set to False to get only redirectpages,
|
||||
unset/None results in not filtering
|
||||
@type filter_redirects bool/None
|
||||
"""
|
||||
# Iterate over articles in redfam
|
||||
for article in self._articlesList:
|
||||
yield pywikibot.Page(pywikibot.Link(article), self.site)
|
||||
page = pywikibot.Page(pywikibot.Link(article), self.site)
|
||||
|
||||
# Filter non existing Pages if requested with filter_existing=True
|
||||
if filter_existing and not page.exists():
|
||||
continue
|
||||
# Filter existing pages if requested with filter_existing=False
|
||||
elif filter_existing is False and page.exists():
|
||||
continue
|
||||
|
||||
# Filter redirects if requested with filter_redirects=True
|
||||
if filter_redirects and page.isRedirectPage():
|
||||
continue
|
||||
# Filter noredirects if requested with filter_redirects=False
|
||||
elif filter_redirects is False and not page.isRedirectPage():
|
||||
continue
|
||||
|
||||
# Yield filtered pages
|
||||
yield page
|
||||
|
||||
def update_status( self ):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user