Spaces:
Running
Running
Download utils/business_type.py from Success-dev/venthrive-api: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/Success-dev/venthrive-api/resolve/main/utils/business_type.py
- Command line
-
hf download hf://spaces/Success-dev/venthrive-api/utils/business_type.py
-
curl -L -o business_type.py https://huggingface.co/spaces/Success-dev/venthrive-api/resolve/main/utils/business_type.py
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, | |
| } | |