Skip to content

Commit

Permalink
added custom seperator for Document.export_kv_to_csv()
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuukwudi committed Oct 30, 2024
1 parent 5581984 commit 826d6dc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions textractor/entities/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ def export_kv_to_csv(
include_kv: bool = True,
include_checkboxes: bool = True,
filepath: str = "Key-Values.csv",
sep: str = ";",
):
"""
Export key-value entities and checkboxes in csv format.
Expand All @@ -579,6 +580,8 @@ def export_kv_to_csv(
:type include_checkboxes: bool
:param filepath: Path to where file is to be stored.
:type filepath: str
:param sep: Separator to be used in the csv file.
:type sep: str
"""
keys = []
values = []
Expand All @@ -597,9 +600,9 @@ def export_kv_to_csv(
values.append(kv.value.children[0].status.name)

with open(filepath, "w") as f:
f.write(f"Key;Value{os.linesep}")
f.write(f"Key{sep}Value{os.linesep}")
for k, v in zip(keys, values):
f.write(f"{k};{v}{os.linesep}")
f.write(f"{k}{sep}{v}{os.linesep}")

logging.info(
f"csv file stored at location {os.path.join(os.getcwd(),filepath)}"
Expand Down

0 comments on commit 826d6dc

Please sign in to comment.