From 90da23171211bab0ea1fe4a534dbcbe39150b98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Fri, 11 Sep 2015 17:05:18 +0200 Subject: [PATCH] Move the code for instanciating of RED_FAM_PARSER to the end of loop --- red_page.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/red_page.py b/red_page.py index d2452e0..0d7d2f3 100644 --- a/red_page.py +++ b/red_page.py @@ -70,7 +70,8 @@ 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 fam_heading = None @@ -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 ): """