The readers flattened a posting's HTML into one line with strip_html, so sections and bullets ran together. _shared.html_text gives a line per paragraph, '• ' before a list item and '## ' before a heading; every reader's description goes through it, sections read per role get their own headings, and the reader pane draws the lines as h3, ul and p. Excerpts leave the marks out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
151 lines
5.7 KiB
Python
151 lines
5.7 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 json
|
|
import logging
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
|
|
from ._contract import Ask, Fields, Place, Reads, Row
|
|
from ._shared import Get, html_text, label_slug_ok, only, parse_dt, place
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
READS = Reads(
|
|
scope="board", listing="whole", text="detail", complete="whole",
|
|
places="one",
|
|
fields=Fields(posted="trusted", remote="stated", employment="stated"),
|
|
robots="read: robots.txt allows /careers (checked 2026-09-29)",
|
|
)
|
|
|
|
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",
|
|
)
|
|
|
|
#: 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 feed_url(slug: str, ask: Ask) -> str:
|
|
return f"https://{host(slug)}/careers/list"
|
|
|
|
|
|
def _remote(j: dict[str, Any]) -> bool | str | None:
|
|
"""`isRemote` when true, else `locationType` as the host writes it ("0", "1", "2")."""
|
|
if j.get("isRemote") is True:
|
|
return True
|
|
return None if j.get("locationType") is None else str(j["locationType"]).strip() or None
|
|
|
|
|
|
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 _places(j: dict[str, Any]) -> list[Place]:
|
|
"""The one place BambooHR states, if it states any."""
|
|
text = _place(j)
|
|
return [place(text)] if text else []
|
|
|
|
|
|
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
|
|
places = _places(j)
|
|
row: Row = {
|
|
"source_id": source_id,
|
|
"title": title,
|
|
"places": places,
|
|
"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
|
|
}
|
|
if employment := str(j.get("employmentStatusLabel") or "").strip():
|
|
row["employment"] = employment
|
|
out.append(row)
|
|
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": html_text(opening.get("description")),
|
|
"posted": parse_dt(opening.get("datePosted")),
|
|
}
|
|
if place := _place(opening):
|
|
out["location"] = place
|
|
out["places"] = _places(opening)
|
|
if (remote := _remote(opening)) is not None:
|
|
out["remote"] = remote
|
|
return out
|