diff options
| author | Alex Schofield <git@ajschof.me> | 2025-02-20 18:27:12 +0000 |
|---|---|---|
| committer | Alex Schofield <git@ajschof.me> | 2025-02-20 18:27:12 +0000 |
| commit | 70a16769761450b9c2aa63cda86a30a73bc0217c (patch) | |
| tree | b9b86ac8575e12f30bc0e53233c94b4ab99973b6 /gdpr_obfuscator/write.py | |
| parent | 9827fcf1a40b0c4993da3f420177f4e390e038e9 (diff) | |
| download | gdpr-obfuscator-70a16769761450b9c2aa63cda86a30a73bc0217c.tar.gz gdpr-obfuscator-70a16769761450b9c2aa63cda86a30a73bc0217c.zip | |
update pyproject.toml & references with new src folder name
Diffstat (limited to 'gdpr_obfuscator/write.py')
| -rw-r--r-- | gdpr_obfuscator/write.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gdpr_obfuscator/write.py b/gdpr_obfuscator/write.py new file mode 100644 index 0000000..451b073 --- /dev/null +++ b/gdpr_obfuscator/write.py @@ -0,0 +1,28 @@ +import csv +import io +from typing import List, Dict +from obfuscator.logger import get_logger + +logger = get_logger("CSVWRITER") + + +class DataWriter: + def __init__(self): + pass + + def create_byte_stream(self, data: List[Dict[str, str]]) -> bytes: + if not data: + logger.error("Invalid or empty 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() + + return csv_string.encode("utf-8") |
