Files
jobboard/plugins/readers/bamboohr.py
T
WolfandClaude Opus 5.5 73dec9028e Rename plugins/atshosts to plugins/readers
Every import, test and live doc follows the new path; behaviour is unchanged.
tests/test_atshosts.py becomes tests/test_readers.py. plan-readers.md and
review-ingest.md keep the old name, since they describe the state before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 08:48:30 +02:00

136 lines
5.1 KiB
Python

"""BambooHR: `bamboohr:<subdomain>` for acme.bamboohr.com, the whole board in
one JSON answer and each role's text, date and country on its own page.
Written from Configit's board on 2026-09-29 (two roles); jobhunt-hq did not
read BambooHR. Unverified: whether a large board pages `/careers/list` (this
one states `meta.totalCount` and no paging keys, so a list shorter than its
count is refused rather than read as the whole board), and the words of
`locationType`, taken to be BambooHR's own settings, "0" in the office, "1"
remote and "2" hybrid; Configit's hybrid roles say "2" and `isRemote` is null.
A posting that invites an unsolicited application without a role (Configit's
first) is listed like any other role.
"""
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, Row, label_slug_ok, only, parse_dt
NAME = "bamboohr"
LABEL = "BambooHR"
PATTERNS = (
# Not the company's own app or documentation subdomains, which BambooHR
# itself serves and which name no board.
r"https?://(?!(?:app|resources|documentation|help)\.)([a-z0-9-]+)\.bamboohr\.com",
)
#: `locationType` -> `store._remote`'s words. Anything else says nothing.
_REMOTE = {"0": "onsite", "1": "remote", "2": "hybrid"}
#: Sent on the detail read: without it the same URL answers the page's HTML.
_JSON = {"Accept": "application/json"}
def host(slug: str) -> str:
return f"{slug.lower()}.bamboohr.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)}/careers"
def robots_page(slug: str) -> str:
return careers_url(slug)
def feed_url(slug: str) -> str:
return f"https://{host(slug)}/careers/list"
def _remote(j: dict[str, Any]) -> str | None:
if j.get("isRemote") is True:
return "remote"
return _REMOTE.get(str(j.get("locationType") if j.get("locationType") is not None else ""))
def _place(j: dict[str, Any]) -> str:
"""City, state and country of a role, as far as either of its two
location objects states them (`atsLocation` mirrors `location` and is
filled by companies that use BambooHR's own applicant tracking)."""
place, ats_place = j.get("location") or {}, j.get("atsLocation") or {}
country = place.get("addressCountry") or ats_place.get("country")
parts = (place.get("city") or ats_place.get("city"),
place.get("state") or ats_place.get("state"), country)
return ", ".join(str(p).strip() for p in parts if p and str(p).strip())
def parse(body: bytes, slug: str) -> list[Row]:
"""`/careers/list` -> `{"meta": {"totalCount": n}, "result": [...]}`. A
role has `id`, `jobOpeningName`, `departmentLabel`, `location` (`city`,
`state`), `atsLocation` (the same with a `country`, null so far),
`isRemote` and `locationType`. The text, the date and the country are only
on the role's own page (`detail`), which is why `description` and `posted`
are empty here."""
data = json.loads(body)
listed = data.get("result") if isinstance(data, dict) else None
if not isinstance(listed, list):
raise ValueError("not a BambooHR listing: no result list")
stated = (data.get("meta") or {}).get("totalCount")
if isinstance(stated, int) and stated > len(listed):
raise ValueError(f"BambooHR listing has {len(listed)} of {stated} roles")
out = []
for j in listed:
title = (j.get("jobOpeningName") or "").strip()
source_id = str(j.get("id") or "")
if not title or not source_id:
continue
out.append({
"source_id": source_id,
"title": title,
"location": _place(j),
"url": f"https://{host(slug)}/careers/{source_id}",
"posted": None,
"department": str(j.get("departmentLabel") or "").strip(),
"description": "",
"remote": _remote(j),
"salary_text": "", # the list states no pay; the detail's `compensation` was null
})
return out
def detail(get: Get, slug: str, row: Row) -> dict[str, Any]:
"""`/careers/<id>/detail` -> `{"result": {"jobOpening": {...}}}`, with the
HTML `description`, `datePosted` (a date), `location` (`city`, `state`,
`addressCountry`) and `locationType`. The location is the listing's with
the country added, since the listing has none."""
data = json.loads(get(f"https://{host(slug)}/careers/{row['source_id']}/detail",
headers=_JSON))
opening = ((data.get("result") or {}).get("jobOpening")
if isinstance(data, dict) else None)
if not isinstance(opening, dict):
raise ValueError("not a BambooHR role: no result.jobOpening")
out: dict[str, Any] = {
"description": " ".join(html.unescape(strip_html(opening.get("description") or "")).split()),
"posted": parse_dt(opening.get("datePosted")),
}
if place := _place(opening):
out["location"] = place
if remote := _remote(opening):
out["remote"] = remote
return out