diff --git a/plugins/atshosts/bamboohr.py b/plugins/atshosts/bamboohr.py new file mode 100644 index 0000000..0a558a2 --- /dev/null +++ b/plugins/atshosts/bamboohr.py @@ -0,0 +1,135 @@ +"""BambooHR: `bamboohr:` 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//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 diff --git a/tests/fixtures/ats/bamboohr-detail-26.json b/tests/fixtures/ats/bamboohr-detail-26.json new file mode 100644 index 0000000..523e39b --- /dev/null +++ b/tests/fixtures/ats/bamboohr-detail-26.json @@ -0,0 +1 @@ +{"meta":{},"result":{"jobOpening":{"jobOpeningShareUrl":"https:\/\/configit.bamboohr.com\/careers\/26","jobOpeningName":"Unsolicited application - All Configit locations","jobOpeningStatus":"Open","jobCategoryId":null,"departmentId":null,"departmentLabel":"","employmentStatusLabel":"Full-Time","employmentType":null,"location":{"city":"K\u00f8benhavn \u00d8","state":null,"postalCode":"2100","addressCountry":"Denmark"},"atsLocation":{"country":null,"countryId":null,"state":null,"city":null},"description":"

Hi,<\/p>\n


<\/p>\n

If there is currently no vacant position that matches your skills, you are welcome to send us an unsolicited application.<\/p>\n


<\/p>\n

We are curious to hear about you and why you'd like to join us.<\/p>\n


<\/p>\n

Please also let us know in which of our locations you'd like to work:<\/p>\n


<\/p>\n