Move the code for instanciating of RED_FAM_PARSER to the end of loop
This commit is contained in:
42
red_page.py
42
red_page.py
@@ -70,6 +70,7 @@ class RED_PAGE:
|
|||||||
|
|
||||||
# Since @param text is a string we need to split it in lines
|
# Since @param text is a string we need to split it in lines
|
||||||
text_lines = self.page.text.split( "\n" )
|
text_lines = self.page.text.split( "\n" )
|
||||||
|
length = len( text_lines )
|
||||||
|
|
||||||
# Initialise line counter
|
# Initialise line counter
|
||||||
i = 0
|
i = 0
|
||||||
@@ -86,18 +87,6 @@ class RED_PAGE:
|
|||||||
# Check wether we have an "Redundance-Family"-Section heading (Level 3)
|
# Check wether we have an "Redundance-Family"-Section heading (Level 3)
|
||||||
if RED_FAM_PARSER.is_sectionheading( line ):
|
if RED_FAM_PARSER.is_sectionheading( line ):
|
||||||
|
|
||||||
# Before working with next red_fam create the object for the one before (if one)
|
|
||||||
if( fam_heading and beginning ):
|
|
||||||
#Maybe we can find a ending by feed
|
|
||||||
if not ending:
|
|
||||||
j = i
|
|
||||||
while (j > last_fam) and not ending:
|
|
||||||
j -= 1
|
|
||||||
ending = RED_FAM_PARSER.is_ending2( text_lines[ j ] )
|
|
||||||
|
|
||||||
red_fam = RED_FAM_PARSER( fam_heading, self.page._pageid, self.is_archive(), beginning, ending )
|
|
||||||
print( red_fam )
|
|
||||||
|
|
||||||
# Save line number for last detected Redundance-Family
|
# Save line number for last detected Redundance-Family
|
||||||
last_fam = i
|
last_fam = i
|
||||||
# Save heading
|
# Save heading
|
||||||
@@ -116,16 +105,31 @@ class RED_PAGE:
|
|||||||
beginning = RED_FAM_PARSER.is_beginning( line )
|
beginning = RED_FAM_PARSER.is_beginning( line )
|
||||||
elif not ending:
|
elif not ending:
|
||||||
ending = RED_FAM_PARSER.is_ending( line )
|
ending = RED_FAM_PARSER.is_ending( line )
|
||||||
|
|
||||||
|
# Detect end of red_fam section (next line is new sectionheading) or end of file
|
||||||
|
# Prevent from running out of index
|
||||||
|
if i < (length - 1):
|
||||||
|
test = RED_FAM_PARSER.is_sectionheading( text_lines[ i + 1 ] )
|
||||||
|
else:
|
||||||
|
test = False
|
||||||
|
if ( test or ( length == ( i + 1 ) ) ):
|
||||||
|
|
||||||
|
# Create the red_fam object
|
||||||
|
if( fam_heading and beginning ):
|
||||||
|
|
||||||
|
#Maybe we can find a ending by feed if we have None yet (No done notice on archive pages)
|
||||||
|
if not ending and self.is_archive():
|
||||||
|
j = i
|
||||||
|
while (j > last_fam) and not ending:
|
||||||
|
j -= 1
|
||||||
|
ending = RED_FAM_PARSER.is_ending2( text_lines[ j ] )
|
||||||
|
|
||||||
|
red_fam = RED_FAM_PARSER( fam_heading, self.page._pageid, self.is_archive(), beginning, ending )
|
||||||
|
pywikibot.output( red_fam )
|
||||||
|
|
||||||
# Increment line counter
|
# Increment line counter
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
# For the last red_fam create the object
|
|
||||||
if( fam_heading and beginning ):
|
|
||||||
#~ try:
|
|
||||||
red_fam = RED_FAM_PARSER( fam_heading, self.page._pageid, self.is_archive(), beginning, ending )
|
|
||||||
#~ except:
|
|
||||||
#~ pass
|
|
||||||
# Set status of red_page to parsed
|
|
||||||
self.__parsed = True
|
self.__parsed = True
|
||||||
def __update_db( self ):
|
def __update_db( self ):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user