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 (#64)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user