@@ -99,25 +99,14 @@ def get_search_service():
9999 )
100100
101101
102- def initialize_data_file (file_path , header ):
103- if not os .path .isfile (file_path ):
104- with open (file_path , "w" , encoding = "utf-8" , newline = "\n " ) as file_obj :
105- writer = csv .DictWriter (
106- file_obj , fieldnames = header , dialect = "unix"
107- )
108- writer .writeheader ()
109-
110-
111102def initialize_all_data_files (args ):
112- if not args .enable_save :
113- return
114-
115- # Create data directory for this phase
116- os .makedirs (PATHS ["data_phase" ], exist_ok = True )
117-
118- initialize_data_file (FILE1_COUNT , HEADER1_COUNT )
119- initialize_data_file (FILE2_LANGUAGE , HEADER2_LANGUAGE )
120- initialize_data_file (FILE3_COUNTRY , HEADER3_COUNTRY )
103+ for file_path , header in [
104+ (FILE1_COUNT , HEADER1_COUNT ),
105+ (FILE2_LANGUAGE , HEADER2_LANGUAGE ),
106+ (FILE3_COUNTRY , HEADER3_COUNTRY ),
107+ ]:
108+ if not os .path .isfile (file_path ):
109+ shared .rows_to_csv (args , file_path , header , [])
121110
122111
123112def get_last_completed_plan_index ():
@@ -150,8 +139,6 @@ def load_plan():
150139
151140
152141def append_data (args , plan_row , index , count ):
153- if not args .enable_save :
154- return
155142 if plan_row ["COUNTRY" ]:
156143 file_path = FILE3_COUNTRY
157144 fieldnames = HEADER3_COUNTRY
@@ -178,11 +165,7 @@ def append_data(args, plan_row, index, count):
178165 "TOOL_IDENTIFIER" : plan_row ["TOOL_IDENTIFIER" ],
179166 "COUNT" : count ,
180167 }
181- with open (file_path , "a" , encoding = "utf-8" , newline = "\n " ) as file_obj :
182- writer = csv .DictWriter (
183- file_obj , fieldnames = fieldnames , dialect = "unix"
184- )
185- writer .writerow (row )
168+ shared .rows_to_csv (args , file_path , fieldnames , [row ], append = True )
186169
187170
188171def query_gcs (args , service , last_completed_plan_index , plan ):
0 commit comments