From 34755c557b458dad40af5059118715e111388eec Mon Sep 17 00:00:00 2001 From: gradedSystem Date: Tue, 4 Feb 2025 10:31:30 +0800 Subject: [PATCH] [fix][m] Fixing newline behaviour \r\n to \n --- scripts/prepare.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/prepare.py b/scripts/prepare.py index d8654fb5d8..dadd346548 100644 --- a/scripts/prepare.py +++ b/scripts/prepare.py @@ -9,6 +9,14 @@ data_file_path = os.path.join('data', 'subdivision-codes.csv') +def fix_crlf(csv_file, output_file): + # Read the CSV file and replace \r\n with \n + with open(csv_file, "rb") as f: + content = f.read().replace(b"\r\n", b"\n") + + with open(output_file, "wb") as f: + f.write(content) + def fix_multiline_csv(file_path): with open(file_path, 'r', encoding='utf-8') as infile: lines = infile.readlines() @@ -168,7 +176,7 @@ def process(extracted_files): # Loop over the file paths and call remove_double_quotes for each for file_path in file_paths: remove_double_quotes(file_path) - + fix_crlf(file_path, file_path) fix_multiline_csv(data_file_path) for file_path in cleaned_files: