Skip to content

Commit

Permalink
[fix][m] Fixing newline behaviour \r\n to \n
Browse files Browse the repository at this point in the history
  • Loading branch information
gradedSystem committed Feb 4, 2025
1 parent edc2dcd commit 34755c5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion scripts/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 34755c5

Please sign in to comment.