Andrey Epifancev b2a89394c9 synthgen: словарь компаний, состав группы, выгрузка ЕЦП (#38)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 23:39:15 +04:00

35 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Словарь вымышленных организаций (спека §4.1): чтение закоммиченного `companies.csv`.
Это пакет (а не модуль `dictionary.py`), чтобы работал `python -m synthgen.dictionary.build` (решение 17).
"""
import csv
from dataclasses import dataclass
from pathlib import Path
CSV_PATH = Path(__file__).with_name("companies.csv")
HEADER = ["name", "form", "inn", "kpp", "kind"]
@dataclass(frozen=True)
class Org:
"""Организация словаря. `name` — как её пишет 1С: `Северная Нива ООО`, `Аверина Е.И. ИП`."""
name: str
form: str # ООО | АО | ПАО | ИП
inn: str
kpp: str # у ИП пусто
kind: str # отрасль или «банк»
@property
def root(self) -> str:
"""Имя без формы: `Северная Нива`."""
return self.name.rsplit(" ", 1)[0]
def load(path: Path | None = None) -> list[Org]:
"""Организации словаря в порядке файла."""
with (path or CSV_PATH).open(encoding="utf-8", newline="") as fh:
reader = csv.DictReader(fh, delimiter=";")
return [Org(r["name"], r["form"], r["inn"], r["kpp"], r["kind"]) for r in reader]