From 2633f1c9e8c8d32770b65a11fc881f7f87af72a3 Mon Sep 17 00:00:00 2001 From: yulin_luo Date: Tue, 2 Jan 2024 16:10:14 -0800 Subject: [PATCH 1/2] ignore .vscode --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 044ba5f..e04b24c 100644 --- a/.gitignore +++ b/.gitignore @@ -161,3 +161,6 @@ cython_debug/ # macOS .DS_Store + +# VS Code +.vscode \ No newline at end of file From bd2297e5cd5c827f71500b32681ba23a66b0ffbe Mon Sep 17 00:00:00 2001 From: yulin_luo Date: Tue, 2 Jan 2024 19:21:29 -0800 Subject: [PATCH 2/2] merge same values in columns: company and recipient_mail --- main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index eba6213..e6f395f 100644 --- a/main.py +++ b/main.py @@ -12,9 +12,14 @@ # Configure logging logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s') -def format_cell(item): +def format_cell(key, item): "Join list elements with a newline character, remove square brackets" if isinstance(item, list): + if key in ['company', 'recipient_mail']: + # merge repeating values to a single value + if len(set(item)) == 1: + return str(item[0]) + return '\n'.join(map(str, item)) return str(item) @@ -80,7 +85,7 @@ def export_to_csv(data, filename): for row in data: # remove square and curly brackets # separate each item to a new line in a cell - formatted_row = {key: format_cell(value) for key, value in row.items()} + formatted_row = {key: format_cell(key, value) for key, value in row.items()} formatted_row['state'] = remove_curly_braces(formatted_row['state']) writer.writerow(formatted_row)