mirror of
https://github.com/complexcaresolutions/dak.c2s.git
synced 2026-03-17 18:23:42 +00:00
fix: auto-detect CSV delimiter (comma, semicolon, tab)
German Excel/CRM exports often use semicolons instead of commas. The parser now uses csv.Sniffer to auto-detect the delimiter, fixing the issue where semicolon-delimited CSVs produced 0 rows. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f8a8befb19
commit
400520aebd
1 changed files with 10 additions and 1 deletions
|
|
@ -76,7 +76,16 @@ def parse_csv(content: bytes, filename: str = "") -> list[ParsedCase]:
|
||||||
and logged.
|
and logged.
|
||||||
"""
|
"""
|
||||||
text = content.decode("utf-8-sig") # Handle BOM
|
text = content.decode("utf-8-sig") # Handle BOM
|
||||||
reader = csv.DictReader(io.StringIO(text))
|
|
||||||
|
# Auto-detect delimiter (comma vs semicolon) from first few lines
|
||||||
|
try:
|
||||||
|
dialect = csv.Sniffer().sniff(text[:2048], delimiters=",;\t")
|
||||||
|
delimiter = dialect.delimiter
|
||||||
|
except csv.Error:
|
||||||
|
delimiter = ","
|
||||||
|
logger.debug("CSV delimiter detected as %r for %s", delimiter, filename)
|
||||||
|
|
||||||
|
reader = csv.DictReader(io.StringIO(text), delimiter=delimiter)
|
||||||
cases: list[ParsedCase] = []
|
cases: list[ParsedCase] = []
|
||||||
errors: list[str] = []
|
errors: list[str] = []
|
||||||
skipped = 0
|
skipped = 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue