Skip to content

Commit

Permalink
Merge pull request #39 from Mive667/Merge-same-values-in-cells
Browse files Browse the repository at this point in the history
Merge same values in cells
  • Loading branch information
Windsooon authored Jan 6, 2024
2 parents 3ce2280 + bd2297e commit 4d3e0d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ cython_debug/

# macOS
.DS_Store

# VS Code
.vscode
9 changes: 7 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 4d3e0d6

Please sign in to comment.