venthrive-api / utils /business_type.py
GitHub Actions
Sync from GitHub 路 2026-10-22 20:43 UTC
89a70e2
Raw History Blame Contribute Delete
1.02 kB
"""
Readable sector / type of business / niche from a BFF section1 doc.
section1 stores only ids (sectorId, subsectorId, nicheId), plus customNiche when
nicheId is "other". Sub-sector labels come from the exported subsectors.json;
sector and niche ids are snake_case, so they read fine once humanised.
"""
from news.business_types import SUBSECTORS
OTHER_NICHE_ID = "other"
_SUBSECTOR_LABELS = {s["id"]: s["label"] for s in SUBSECTORS}
def _humanise(id_: str) -> str:
return id_.replace("_", " ").strip().capitalize()
def describe(s1: dict) -> dict:
"""{'sector': ..., 'subsector': ..., 'niche': ...}, '' for anything not set."""
sub_id = s1.get("subsectorId", "")
niche_id = s1.get("nicheId", "")
if niche_id == OTHER_NICHE_ID:
niche = (s1.get("customNiche") or "").strip()
else:
niche = _humanise(niche_id)
return {
"sector": _humanise(s1.get("sectorId", "")),
"subsector": _SUBSECTOR_LABELS.get(sub_id, _humanise(sub_id)),
"niche": niche,
}