"""Workable: `workable:`, paged ten roles at a time with a stated total. Written from one real board, Hugging Face's, on 2026-09-28, when the first board with roles was seen; jobhunt-hq did not read Workable. """ from __future__ import annotations import json import logging from collections.abc import Callable from typing import Any from ._contract import Ask, Fields, Place, Reads from ._shared import Get, Page, Row, only, parse_dt, path_slug_ok log = logging.getLogger(__name__) NAME = "workable" LABEL = "Workable" RANK = 40 PATTERNS = ( r"apply\.workable\.com/(?:api/v\d/accounts/)?([A-Za-z0-9_-]+)", r"https?://(?!apply\.|www\.)([a-z0-9-]+)\.workable\.com", ) READS = Reads( scope="board", listing="paged", page_size=10, text="none", complete="stated", places="many", fields=Fields(posted="trusted", remote="stated", country="stated", employment="stated"), robots="api: no robots.txt check needed (public board API), 2026-09-30", ) _API = "apply.workable.com" #: `type` -> the app's employment words; a type not listed is logged at debug #: level so the table can grow. _EMPLOYMENT = {"full": "full_time", "part": "part_time", "contract": "contract", "temporary": "temporary", "internship": "internship"} # No probe: Workable's API sits behind a rate limit that a run of guesses # trips, and a Workable site links its board plainly anyway. def slug_ok(slug: str) -> bool: return path_slug_ok(slug) def allowed(slug: str) -> Callable[[str], bool]: return only(_API) def careers_url(slug: str) -> str: return f"https://{_API}/{slug}" def page(get: Get, slug: str, cursor: Any, ask: Ask = Ask()) -> Page: """One POST of the list; the next page is the same POST with `{"token": nextPage}`, and the last page has no `nextPage`.""" url = f"https://{_API}/api/v3/accounts/{slug}/jobs" data = json.loads(get(url, method="POST", payload={"token": cursor} if cursor else {})) return data, data.get("results") or [], data.get("total"), data.get("nextPage") or None def parse(body: bytes, slug: str) -> list[Row]: return rows(json.loads(body), slug) def _places(job: dict[str, Any], remote: bool) -> tuple[list[Place], set[str]]: """Every place of a role and the countries' codes among them. `locations` lists them (city, region, country; `hidden` ones are stated too), and `location` is the first alone, the fallback for a role that lists none. A place is remote when the role is.""" found: list[Place] = [] codes: set[str] = set() listed = [loc for loc in job.get("locations") or [] if isinstance(loc, dict)] for loc in listed or [job.get("location") or {}]: parts: list[str] = [] for part in (loc.get("city"), loc.get("region"), loc.get("country")): part = str(part or "").strip() if part and part not in parts: parts.append(part) text = ", ".join(parts) if text and text not in (p["text"] for p in found): found.append({"text": text, "remote": remote}) if code := str(loc.get("countryCode") or "").strip().upper(): codes.add(code) return found, codes def rows(data: dict[str, Any], slug: str) -> list[Row]: """One page of POST https://apply.workable.com/api/v3/accounts/{slug}/jobs -> `{"total": int, "results": [...], "nextPage": token}`, as Hugging Face's board answered on 2026-09-28. A result carries no URL and no text: the job page is `https://apply.workable.com/{slug}/j/{shortcode}/`, and the description is only on the per-job endpoint, one request per role, so `description` stays empty here as it does for SmartRecruiters. `location` is the first place and `locations` all of them; `department` is a list; `remote` is a flag beside `workplace` (remote, hybrid, on_site); `type` is the hours or the contract (full, part, ...).""" out = [] for j in data.get("results") or []: title = (j.get("title") or "").strip() shortcode = (j.get("shortcode") or "").strip() if not title or not shortcode: continue remote = bool(j.get("remote")) or j.get("workplace") == "remote" places, codes = _places(j, remote) kind = str(j.get("type") or "").strip().lower() if kind and kind not in _EMPLOYMENT: log.debug("workable: unknown type %r", kind) dept = j.get("department") or "" if isinstance(dept, list): dept = ", ".join(d for d in dept if d) out.append({ "source_id": str(j.get("id") or shortcode), "title": title, "places": places, "location": "; ".join(p["text"] for p in places), "url": f"https://{_API}/{slug}/j/{shortcode}/", "posted": parse_dt(j.get("published")), "department": dept.strip(), "description": "", "remote": remote, "salary_text": "", # Workable's list endpoint states no pay at all "country": next(iter(codes)) if len(codes) == 1 else None, "employment": _EMPLOYMENT.get(kind), }) return out