diff --git a/utils/csv_utils.py b/utils/csv_utils.py index 87aed6f..a57ae83 100644 --- a/utils/csv_utils.py +++ b/utils/csv_utils.py @@ -24,11 +24,17 @@ def write_to_csv_file(rows, file_path: Path, rows_type, fieldnames=None): raise Exception("rows_type value is invalid!") -def append_to_csv_file(rows, file_path: Path): +def append_to_csv_file(rows, file_path: Path, rows_type, fieldnames=None): file_path.parent.mkdir(parents=True, exist_ok=True) with open(file_path, mode="a", newline="") as csvfile: - csv_writer = csv.writer(csvfile) - return csv_writer.writerows(rows) + if rows_type is list: + csv_writer = csv.writer(csvfile) + return csv_writer.writerows(rows) + elif rows_type is dict: + csv_writer = csv.DictWriter(csvfile, fieldnames=fieldnames) + csv_writer.writerows(rows) + else: + raise Exception("rows_type value is invalid!") def convert_config_to_key_val_dict(config: list):