Files
jobboard/plugins/readers/hibob.py
T

125 lines
5.3 KiB
Python

"""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 json
import logging
from collections.abc import Callable
from typing import Any
from ._contract import Ask, Fields, Reads, Row
from ._shared import Get, Page, html_text, label_slug_ok, num, only, parse_dt, pay_line, yearly_amount
log = logging.getLogger(__name__)
# One ad names one site: a company that hires at two sites posts two ads with
# their own ids (Dixa's "Expression of interest" at Copenhagen and London), so
# the host publishes one posting per place.
READS = Reads(
scope="board", listing="paged", text="listing", complete="end",
places="copies",
fields=Fields(pay="figures", posted="listed", remote="stated", employment="stated"),
robots=("read: /api/job-ad on <slug>.careers.hibob.com, whose /robots.txt answers the "
"single-page app's index page, no rules (dixa, checked 2026-09-30)"),
)
NAME = "hibob"
LABEL = "HiBob"
PATTERNS = (r"https?://([a-z0-9-]+)\.careers\.hibob\.com",)
#: 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 page(get: Get, slug: str, cursor: Any, ask: Ask) -> 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()
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 = "\n".join(part for key in _SECTIONS
if (part := html_text(ad.get(key))))
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})
remote = {"remote": True, "hybrid": False, "on_site": False, "onsite": False}.get(
str(ad.get("workspaceTypeId") or "").strip().lower())
row: Row = {
"source_id": ad_id,
"title": title,
"places": [{"text": location, "remote": remote}] if location else [],
"location": location,
"url": f"https://{_host(slug)}/jobs/{ad_id}",
"posted": parse_dt(ad.get("publishedAt")),
"department": str(ad.get("department") or "").strip(),
"description": text,
"remote": str(ad.get("workspaceTypeId") or "").strip() or None,
"salary_text": pay_line(lo, hi, currency, period),
"salary_min": salary_min,
"salary_max": salary_max,
"currency": code,
}
if employment := str(ad.get("employmentType") or "").strip():
row["employment"] = employment
out.append(row)
return out