From e5989305a4a2fe44f4e17d7548fad5fbcdbf8421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Sun, 28 Aug 2016 13:20:13 +0200 Subject: [PATCH 1/2] Add a generator to redfam yielding article pages To work on articles of a redfam a generator which yields belonging articles is necessary Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=87 FS#87] --- lib/redfam.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/redfam.py b/lib/redfam.py index b2277fc..284b54e 100644 --- a/lib/redfam.py +++ b/lib/redfam.py @@ -57,6 +57,9 @@ class RedFam: @param heading str Original heading of RedFam (Link) """ + # Having pywikibot.Site() is a good idea most of the time + self.site = pywikibot.Site() + # Database interface self._mysql = MysqlRedFam( fam_hash ) @@ -455,6 +458,15 @@ class RedFamWorker( RedFam ): # with wrong month abreviations in strptime locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') + def article_generator(self): + """ + Yields pywikibot pageobjects for articles belonging to this redfams + in a generator + self. + """ + for article in self._articlesList: + yield pywikibot.Page(pywikibot.Link(article), self.site) + def update_status( self ): """ Sets status to 3 when worked on From c0b18f88e5ea4cb3654b7e92bf9adfcba16b4e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Sun, 28 Aug 2016 15:06:17 +0200 Subject: [PATCH 2/2] 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] --- lib/redfam.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/redfam.py b/lib/redfam.py index 284b54e..9889908 100644 --- a/lib/redfam.py +++ b/lib/redfam.py @@ -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 ): """