refactor: fix review issues — reuse entity_to_row, public parse_row, validate dates

- scan.py: use entity_to_row from csv_utils instead of duplicated _fmt
- csv_utils: rename _parse_row to parse_row (public API)
- backup.py: use public parse_row
- cli.py: validate --start < --end in backup command

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-21 16:06:51 +08:00
parent 57c985ee3e
commit a36bfcc0f0
4 changed files with 11 additions and 15 deletions

View File

@@ -32,7 +32,7 @@ def entity_to_row(entity: dict[str, Any]) -> dict[str, str]:
return {col: _format_value(entity.get(col)) for col in CSV_COLUMNS}
def _parse_row(raw: dict[str, str]) -> dict[str, Any]:
def parse_row(raw: dict[str, str]) -> dict[str, Any]:
result: dict[str, Any] = {}
for col in CSV_COLUMNS:
val = raw.get(col, "")
@@ -51,7 +51,7 @@ def _parse_row(raw: dict[str, str]) -> dict[str, Any]:
def row_to_entity(raw: dict[str, str]) -> dict[str, Any]:
return _parse_row(raw)
return parse_row(raw)
def write_csv(path: Path, entities: list[dict[str, Any]]) -> None:
@@ -67,4 +67,4 @@ def read_csv(path: Path):
with open(path, newline="") as f:
reader = csv.DictReader(f)
for row in reader:
yield _parse_row(row)
yield parse_row(row)