def execute(self, *args): output_valid = IOOutput(self._io) output_valid() with open(self._s.cache_file, "r", encoding="utf-8") as f: for l in f: print(l)
def execute(self, *args): super().execute() input_valid = IOOutput(self._io) input_valid() with open(self._s.cache_file, "r", encoding=self._encoding) as i, open( self._dest_path, self._mode, encoding=self._encoding ) as o: writer = csv.writer(o, quoting=csv.QUOTE_ALL) # write csv header head_dict = ast.literal_eval(i.readline()) header = [] for k in head_dict.keys(): header.append(k) writer.writerow(header) # write as csv per one line i.seek(0) for l_str in i: l_dict = ast.literal_eval(l_str) contents = [] for k, v in l_dict.items(): contents.append(v) writer.writerow(contents) self._s.remove()
def execute(self, *args): super().execute() param_valid = EssentialParameters(self.__class__.__name__, [self._tblname]) param_valid() tbl_valid = SqliteTableExistence(self._dbname, self._tblname) tbl_valid() output_valid = IOOutput(self._io) output_valid() # get table column definition self._sqlite_adptr.connect(self._dbname) column_def = self.__get_column_def() if self._refresh is True: self.__refresh_table(column_def) # database transaction def insert(): self._logger.info("Start to insert") insert_rows = [] with open(self._s.cache_file, "r", encoding="utf-8") as f: for i, l_str in enumerate(f, 1): l_dict = ast.literal_eval(l_str) insert_rows.append(l_dict) # Check only once if i == 1: self.__valid_column_def(column_def, l_dict) # execute bulk insert if i % self._insert_cnt == 0: self._sqlite_adptr.execute_many_insert( self._tblname, column_def, insert_rows, self._replace_into) insert_rows.clear() if len(insert_rows) > 0: self._sqlite_adptr.execute_many_insert( self._tblname, column_def, insert_rows, self._replace_into) insert_rows.clear() self._logger.info("Finish to insert") super().execute(insert) self._s.remove()