fin-hub/src/fin_hub/ingest/_csv.py
tegwick 1abbbe85e4 Implement fin-hub T24-T26: ingest, runway, coupling, RaaS packaging
Add CSV importers, runway calculator, budget alerts, cross-hub coupling
emitters, finhub CLI, and raas-mvp-packaging docs with full test coverage.
2026-07-08 00:59:39 +02:00

28 lines
No EOL
759 B
Python

"""Shared CSV helpers."""
from __future__ import annotations
import csv
from pathlib import Path
def read_csv_rows(path: Path) -> list[dict[str, str]]:
text = path.read_text(encoding="utf-8-sig")
reader = csv.DictReader(text.splitlines())
return [{k.strip(): (v or "").strip() for k, v in row.items() if k} for row in reader]
def pick(row: dict[str, str], *names: str) -> str:
lowered = {k.lower(): v for k, v in row.items()}
for name in names:
value = lowered.get(name.lower())
if value:
return value
return ""
def parse_amount(value: str) -> float:
cleaned = value.replace("", "").replace("EUR", "").replace(",", ".").strip()
if not cleaned:
return 0.0
return float(cleaned)