|
|
@ -28,8 +28,9 @@ Provides a class for handling redundance discussion pages and archives |
|
|
|
import pywikibot # noqa |
|
|
|
import mwparserfromhell as mwparser |
|
|
|
|
|
|
|
import jogobot |
|
|
|
|
|
|
|
from mysqlred import MysqlRedPage |
|
|
|
from redfam import RedFamParser |
|
|
|
|
|
|
|
|
|
|
|
class RedPage: |
|
|
@ -53,10 +54,6 @@ class RedPage: |
|
|
|
self.is_page_changed() |
|
|
|
|
|
|
|
self._parsed = None |
|
|
|
if( self._changed or self.__mysql.data[ 'status' ] == 0 ): |
|
|
|
self.parse() |
|
|
|
|
|
|
|
self.__update_db() |
|
|
|
|
|
|
|
def __handle_db( self ): |
|
|
|
""" |
|
|
@ -95,6 +92,16 @@ class RedPage: |
|
|
|
else: |
|
|
|
return False |
|
|
|
|
|
|
|
def is_parsing_needed( self ): |
|
|
|
""" |
|
|
|
Decides wether current RedPage needs to be parsed or not |
|
|
|
""" |
|
|
|
|
|
|
|
if( self._changed or self.__mysql.data[ 'status' ] == 0 ): |
|
|
|
return True |
|
|
|
else: |
|
|
|
return False |
|
|
|
|
|
|
|
def parse( self ): |
|
|
|
""" |
|
|
|
Handles the parsing process |
|
|
@ -109,27 +116,17 @@ class RedPage: |
|
|
|
# include_lead = if true include first section (intro) |
|
|
|
# include_heading = if true include heading |
|
|
|
fams = self.wikicode.get_sections( |
|
|
|
matches=RedFamParser.is_sectionheading, |
|
|
|
matches=jogobot.config["redundances"]["section_heading_regex"], |
|
|
|
include_lead=False, include_headings=True ) |
|
|
|
|
|
|
|
# Iterate over RedFam |
|
|
|
for fam in fams: |
|
|
|
|
|
|
|
# Extract heading text |
|
|
|
heading = next( fam.ifilter_headings() ).title |
|
|
|
|
|
|
|
# Extract beginnig and maybe ending |
|
|
|
(beginning, ending) = RedFamParser.extract_dates( fam, |
|
|
|
self.is_archive() |
|
|
|
) |
|
|
|
|
|
|
|
# Create the RedFam object |
|
|
|
RedFamParser( heading, self.page._pageid, |
|
|
|
self.is_archive(), beginning, ending ) |
|
|
|
yield fam |
|
|
|
|
|
|
|
else: |
|
|
|
RedFamParser.flush_db_cache() |
|
|
|
self._parsed = True |
|
|
|
self.__update_db() |
|
|
|
|
|
|
|
def __update_db( self ): |
|
|
|
""" |
|
|
|