@@ -100,7 +100,10 @@ def initialize_data_file(file_path, header):
100100 writer .writeheader ()
101101
102102
103- def initialize_all_data_files ():
103+ def initialize_all_data_files (args ):
104+ if not args .enable_save :
105+ return
106+
104107 # Create data directory for this phase
105108 os .makedirs (PATHS ["data_phase" ], exist_ok = True )
106109
@@ -112,17 +115,20 @@ def initialize_all_data_files():
112115def get_last_completed_plan_index ():
113116 last_completed_plan_index = 0
114117 for file_path in [FILE1_COUNT , FILE2_LANGUAGE , FILE3_COUNTRY ]:
115- with open (file_path , "r" , newline = "" ) as file_obj :
116- reader = csv .DictReader (file_obj , dialect = "unix" )
117- for row in reader :
118- pass # skip through to last row
119- try :
120- last_completed_plan_index = max (
121- last_completed_plan_index ,
122- int (row ["PLAN_INDEX" ]),
123- )
124- except UnboundLocalError :
125- pass
118+ try :
119+ with open (file_path , "r" , newline = "" ) as file_obj :
120+ reader = csv .DictReader (file_obj , dialect = "unix" )
121+ for row in reader :
122+ pass # skip through to last row
123+ try :
124+ last_completed_plan_index = max (
125+ last_completed_plan_index ,
126+ int (row ["PLAN_INDEX" ]),
127+ )
128+ except UnboundLocalError :
129+ pass # Data row may not be found with --enable-save, etc.
130+ except FileNotFoundError :
131+ pass # File may not be found without --enable-save, etc.
126132 LOGGER .info (f"Last completed plan index: { last_completed_plan_index } " )
127133 return last_completed_plan_index
128134
@@ -249,7 +255,7 @@ def main():
249255 args = parse_arguments ()
250256 shared .log_paths (LOGGER , PATHS )
251257 service = get_search_service ()
252- initialize_all_data_files ()
258+ initialize_all_data_files (args )
253259 last_completed_plan_index = get_last_completed_plan_index ()
254260 if last_completed_plan_index == 2867 :
255261 LOGGER .info (f"Data fetch completed for { QUARTER } " )
0 commit comments