blob: 3b4496b4e5070c368700787930044932feaedf33 (
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
31
32
33
|
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]
|