Files
jobboard/plugins/atshosts/workable.py
T

86 lines
3.0 KiB
Python

"""Workable: `workable:<account>`, 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
from collections.abc import Callable
from typing import Any
from ._shared import Get, Page, Row, only, parse_dt, path_slug_ok
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",
)
_API = "apply.workable.com"
# 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) -> 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 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 an object and `department` a list; `remote` is a flag
beside `workplace` (remote, hybrid, on_site)."""
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
loc = j.get("location") or {}
location = ", ".join(p for p in (loc.get("city"), loc.get("region"), loc.get("country")) if p)
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,
"location": location,
"url": f"https://{_API}/{slug}/j/{shortcode}/",
"posted": parse_dt(j.get("published")),
"department": dept.strip(),
"description": "",
"remote": bool(j.get("remote")) or j.get("workplace") == "remote",
"salary_text": "", # Workable's list endpoint states no pay at all
})
return out