aboutsummaryrefslogtreecommitdiffstats
path: root/gdpr_obfuscator/utils.py
blob: c8aadb272036c9d3133ad73a2c82c4225aa53ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import csv
import io
from enum import Enum
from typing import List, Dict


class Utilities:

    def __init__(self, logger=None):
        pass

    def get_s3_path(self, uri):
        parts = uri.replace("s3://", "").split("/")
        bucket = parts.pop(0)
        key = "/".join(parts)
        return bucket, key

    def create_byte_stream(self, data: List[Dict[str, str]]) -> bytes:

        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")
git.ajschof.me — hosted by ajschofield — powered by cgit