From 870ed4bf25cbf6688657f3cb8bd6f70b0ab96afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Tue, 30 Aug 2016 17:47:02 +0200 Subject: [PATCH] Update redfam.article_generator use article status To be able to filter articles by status of that article Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=89 FS#89] --- bots/markpages.py | 4 +++- lib/redfam.py | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bots/markpages.py b/bots/markpages.py index 244ba14..aa9597c 100644 --- a/bots/markpages.py +++ b/bots/markpages.py @@ -107,7 +107,9 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat() # We need the talkpage (and only this) of each existing page for talkpage in pagegenerators.PageWithTalkPageGenerator( - redfam.article_generator( filter_existing=True ), + redfam.article_generator( + filter_existing=True, + exclude_article_status=["marked"] ), return_talk_only=True ): # Add reference to redfam to talkpages diff --git a/lib/redfam.py b/lib/redfam.py index d5312ca..d82ffbb 100644 --- a/lib/redfam.py +++ b/lib/redfam.py @@ -633,7 +633,9 @@ class RedFamWorker( RedFam ): # with wrong month abreviations in strptime locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') - def article_generator(self, filter_existing=None, filter_redirects=None ): + def article_generator(self, filter_existing=None, filter_redirects=None, + exclude_article_status=[], + onlyinclude_article_status=[] ): """ Yields pywikibot pageobjects for articles belonging to this redfams in a generator @@ -647,11 +649,22 @@ class RedFamWorker( RedFam ): 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: page = pywikibot.Page(pywikibot.Link(article), self.site) + # Exclude by article status + for status in exclude_article_status: + if self.article_has_status( status, title=article ): + continue + + # Only include by article status + for status in onlyinclude_article_status: + if not self.article_has_status( status, title=article ): + continue + # Filter non existing Pages if requested with filter_existing=True if filter_existing and not page.exists(): continue