Read HiBob's careers boards through the company header the site sends
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eac483ff13
commit
27a7723a1d
4 files changed
+507
No files matched your search
@@ -0,0 +1,113 @@
|
||||
"""HiBob: `hibob:<subdomain>` for <subdomain>.careers.hibob.com, the whole
|
||||
board in one JSON answer.
|
||||
|
||||
Written from Dixa's board (two general-application ads) and Liquidia's (14
|
||||
roles) on 2026-09-29. The careers site's own API,
|
||||
`<subdomain>.careers.hibob.com/api/job-ad`, answers 401 unless the request
|
||||
carries the header `companyIdentifier: <subdomain>`. That header is the
|
||||
company's public subdomain and no key or token, but it is why this is a paged
|
||||
module, whose `page` may send headers, although it reads one page. Every ad
|
||||
comes with its texts, so there is no `detail`. Pay is read from the
|
||||
`payTransparency*` fields as they are named; no board seen so far had them
|
||||
filled, so the period's spelling is a guess.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import html
|
||||
import json
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from desk.sources import strip_html
|
||||
|
||||
from ._shared import Get, Page, Row, label_slug_ok, num, only, parse_dt, pay_line, yearly_amount
|
||||
|
||||
NAME = "hibob"
|
||||
LABEL = "HiBob"
|
||||
PATTERNS = (r"https?://([a-z0-9-]+)\.careers\.hibob\.com",)
|
||||
|
||||
#: HiBob's `workspaceTypeId` -> `store._remote`'s words.
|
||||
_REMOTE = {"remote": "remote", "hybrid": "hybrid", "on_site": "onsite", "onsite": "onsite"}
|
||||
|
||||
#: The texts of an ad, in the order the ad shows them.
|
||||
_SECTIONS = ("description", "responsibilities", "requirements", "benefits")
|
||||
|
||||
#: A pay period's spellings, as the word `pay_line` and `yearly_amount` take.
|
||||
_PERIODS = {"year": "year", "yearly": "year", "annual": "year", "annually": "year",
|
||||
"month": "month", "monthly": "month", "hour": "hour", "hourly": "hour",
|
||||
"day": "day", "daily": "day", "week": "week", "weekly": "week"}
|
||||
|
||||
|
||||
def _host(slug: str) -> str:
|
||||
return f"{slug.lower()}.careers.hibob.com"
|
||||
|
||||
|
||||
def slug_ok(slug: str) -> bool:
|
||||
return label_slug_ok(slug)
|
||||
|
||||
|
||||
def allowed(slug: str) -> Callable[[str], bool]:
|
||||
return only(_host(slug))
|
||||
|
||||
|
||||
def careers_url(slug: str) -> str:
|
||||
return f"https://{_host(slug)}/"
|
||||
|
||||
|
||||
def robots_page(slug: str) -> str:
|
||||
return careers_url(slug)
|
||||
|
||||
|
||||
def page(get: Get, slug: str, cursor: Any) -> Page:
|
||||
"""The one page: every ad, and no total or cursor, so the board is
|
||||
complete when the answer parses. The host's robots.txt is its single-page
|
||||
app's index page (a 200 with no rules), which allows."""
|
||||
data = json.loads(get(f"https://{_host(slug)}/api/job-ad",
|
||||
headers={"companyIdentifier": slug.lower(), "Accept": "application/json"}))
|
||||
ads = data.get("jobAdDetails")
|
||||
if not isinstance(ads, list):
|
||||
raise ValueError("not a HiBob board: no jobAdDetails")
|
||||
return data, [{"id": ad.get("id")} for ad in ads], None, None
|
||||
|
||||
|
||||
def parse(body: bytes, slug: str) -> list[Row]:
|
||||
return rows(json.loads(body), slug)
|
||||
|
||||
|
||||
def rows(data: dict[str, Any], slug: str) -> list[Row]:
|
||||
"""One answer -> one row per ad. `location` is the site with its country
|
||||
(the country left off where the site already names it). `posted` is
|
||||
`publishedAt`, which has nanoseconds. The description joins the ad's
|
||||
texts, which are HTML in the ads with sections and plain text elsewhere."""
|
||||
out = []
|
||||
for ad in data.get("jobAdDetails") or []:
|
||||
title = (ad.get("title") or "").strip()
|
||||
ad_id = str(ad.get("id") or "").strip()
|
||||
if not title or not ad_id:
|
||||
continue
|
||||
site = str(ad.get("site") or "").strip()
|
||||
country = str(ad.get("country") or "").strip()
|
||||
location = f"{site}, {country}" if site and country and country.lower() not in site.lower() \
|
||||
else site or country
|
||||
text = " ".join(strip_html(str(ad.get(key) or "")) for key in _SECTIONS)
|
||||
lo, hi = num(ad.get("payTransparencyMinSalary")), num(ad.get("payTransparencyMaxSalary"))
|
||||
currency = ad.get("payTransparencySalaryCurrency")
|
||||
period = _PERIODS.get(str(ad.get("payTransparencySalaryPayPeriod") or "").strip().lower(), "")
|
||||
salary_min, salary_max, code = yearly_amount(lo, hi, currency, period,
|
||||
{"year": 1, "month": 12})
|
||||
out.append({
|
||||
"source_id": ad_id,
|
||||
"title": title,
|
||||
"location": location,
|
||||
"url": f"https://{_host(slug)}/jobs/{ad_id}",
|
||||
"posted": parse_dt(ad.get("publishedAt")),
|
||||
"department": str(ad.get("department") or "").strip(),
|
||||
"description": " ".join(html.unescape(text).split()),
|
||||
"remote": _REMOTE.get(str(ad.get("workspaceTypeId") or "").strip().lower()),
|
||||
"salary_text": pay_line(lo, hi, currency, period),
|
||||
"salary_min": salary_min,
|
||||
"salary_max": salary_max,
|
||||
"currency": code,
|
||||
})
|
||||
return out
|
||||
Reference in new issue
Block a user