aboutsummaryrefslogtreecommitdiffstats
path: root/obfuscator/csv_writer.py
diff options
context:
space:
mode:
authorAlex <git@ajschof.me>2025-02-18 23:34:53 +0000
committerGitHub <noreply@github.com>2025-02-18 23:34:53 +0000
commitf24955044c4c05e37aba4efb505ec63b44113912 (patch)
treee2096c282bdcab9b7c92e1ed6511f65fdd5caead /obfuscator/csv_writer.py
parenteb0d30d0235dbadd1d5c385a0a49d4cd8aea021e (diff)
parent90542cfe838376988982fb5c9062fc8dee0b7c87 (diff)
downloadgdpr-obfuscator-f24955044c4c05e37aba4efb505ec63b44113912.tar.gz
gdpr-obfuscator-f24955044c4c05e37aba4efb505ec63b44113912.zip
Merge pull request #7 from ajschofield/feat/csv-writer
add create_byte_stream for obfuscation output
Diffstat (limited to 'obfuscator/csv_writer.py')
-rw-r--r--obfuscator/csv_writer.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/obfuscator/csv_writer.py b/obfuscator/csv_writer.py
new file mode 100644
index 0000000..aa5ac3f
--- /dev/null
+++ b/obfuscator/csv_writer.py
@@ -0,0 +1,26 @@
+import csv
+import io
+from typing import List, Dict
+from obfuscator.logger import get_logger
+
+# Create the logger
+logger = get_logger("CSVWriter")
+
+
+def create_byte_stream(data: List[Dict[str, str]]) -> bytes:
+ if not data:
+ logger.info("No valid data was provided to write")
+ return b""
+
+ output = io.StringIO()
+
+ headers = list(data[0].keys())
+
+ writer = csv.DictWriter(output, fieldnames=headers)
+ writer.writeheader()
+ writer.writerows(data)
+
+ csv_string = output.getvalue()
+ logger.debug(f"CSV data: {csv_string}")
+
+ return csv_string.encode("utf-8")
git.ajschof.me — hosted by ajschofield — powered by cgit