Move the code for instanciating of RED_FAM_PARSER to the end of loop

This commit is contained in:
2015-09-11 17:05:18 +02:00
parent 529ed09702
commit 90da231712

View File

@@ -70,6 +70,7 @@ class RED_PAGE:
# Since @param text is a string we need to split it in lines
text_lines = self.page.text.split( "\n" )
length = len( text_lines )
# Initialise line counter
i = 0
@@ -86,18 +87,6 @@ class RED_PAGE:
# Check wether we have an "Redundance-Family"-Section heading (Level 3)
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
last_fam = i
# Save heading
@@ -116,16 +105,31 @@ class RED_PAGE:
beginning = RED_FAM_PARSER.is_beginning( line )
elif not ending:
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
i += 1
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
def __update_db( self ):
"""