From dfffe97200e85e767e70ac9a061b23f9619b46cd Mon Sep 17 00:00:00 2001 From: Jonathan Golder Date: Tue, 18 Sep 2018 11:27:41 +0200 Subject: [PATCH] redfam: Add method to check disc section Sometimes disc sections are disapering since the heading is changed and the famhash changes, so we get a new redfam. Mark those as absent Issue #64 (https://git.golderweb.de/wiki/jogobot-red/issues/64) --- lib/redfam.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/redfam.py b/lib/redfam.py index b6192d8..af10178 100644 --- a/lib/redfam.py +++ b/lib/redfam.py @@ -366,6 +366,9 @@ class RedFamParser( RedFam ): - 3 and greater status was set by worker script, do not change it """ + # Since we have parsed it, the section can never be absent + self.status.remove("absent") + # No ending, discussion is running: # Sometimes archived discussions also have no detectable ending if not self.ending and not self.redpage.archive: @@ -674,6 +677,36 @@ class RedFamWorker( RedFam ): # We try it without any more parsing as mw will do while parsing page return ( self.redpage.pagetitle + "#" + anchor_code.strip() ) + def disc_section_exists( self ): + """ + Checks weather the redundance discussion is still existing. Sometimes + it is absent, since heading was changed and therefore we get a + different famhash ergo new redfam. + As a side effect, the method sets status "absent" for missing sections. + + @returns True if it exists otherwise False + @rtype bool + """ + # The redpage + discpage = pywikibot.Page(pywikibot.Site(), self.get_disc_link() ) + + # Parse redpage content + wikicode = mwparser.parse( discpage.get() ) + + # List fams + fams = wikicode.filter_headings( + matches=RedFamParser.is_section_redfam_cb ) + + # Check if current fam is in list of fams + # If not, set status absent and return False + if self.heading not in [ fam.title.strip() for fam in fams]: + self.status.remove("open") + self.status.add("absent") + return False + + # The section exists + return True + def generate_disc_notice_template( self ): """ Generates notice template to add on discussion Pages of Articles when