diff options
Diffstat (limited to 'obfuscator/csv_reader.py')
| -rw-r--r-- | obfuscator/csv_reader.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/obfuscator/csv_reader.py b/obfuscator/csv_reader.py new file mode 100644 index 0000000..b9dccdb --- /dev/null +++ b/obfuscator/csv_reader.py @@ -0,0 +1,34 @@ +import csv +import io +from typing import List, Dict +from obfuscator.logger import get_logger + +logger = get_logger("CSVReader") + + +class CSVReader: + @staticmethod + def read_local(path) -> List[Dict[str, str]]: + logger.debug(f"Reading local CSV from: {path}") + + try: + with open(path, mode="r", encoding="utf-8") as f: + reader = csv.DictReader(f) + return [dict(row) for row in reader] + except FileNotFoundError: + logger.error(f"File not found: {path}") + except Exception as e: + logger.error(f"Error reading file: {e}") + + @staticmethod + def read_s3(path) -> List[Dict[str, str]]: + return [] + + @staticmethod + def read_string(content: str) -> List[Dict[str, str]]: + if not content.strip(): + return [] + + f = io.StringIO(content) + reader = csv.DictReader(f) + return [dict(row) for row in reader] |
