Files
jobboard/plugins/readers/workday.py
T
WolfandClaude Opus 5.5 4316624769 Declare READS for Oracle, Personio, Phenom, Pinpoint, Recruitee, Rippling, SmartRecruiters, SuccessFactors, Teamtailor, Workable and Workday
Every row carries places (Personio additionalOffices, Workable and Recruitee
locations[], every SuccessFactors address, Workday's own read), the list
teaser of Phenom and Oracle is kept in teaser, and the level, employment and
country a host states are mapped. Workday "N Locations" and "Country - City",
and Recruitee "Remote job", are no longer places. Phenom takes dateCreated
as posted. robots_page and ROBOTS_ANY_CASE go; READS.robots records the
decision. Signatures are feed_url(slug, ask) and page(get, slug, cursor, ask),
with an empty Ask as the default so the runner of today still calls them.

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

278 lines
12 KiB
Python

"""Workday: `workday:<tenant>.<wdN>/<Site>`, for example
`workday:lego.wd103/LEGO_External` (the career site
https://lego.wd103.myworkdayjobs.com/LEGO_External), paged by offset with a
total that only the first page states.
The tenant is what the company was named when Workday was set up and is not
always the company (`unitytech`, `novonesis`); the data centre is not
derivable either, and a tenant has several sites, so all three are stored
as they are found. The site is case-insensitive for the API (Red Hat's
`jobs` and `Jobs` both work) but its robots.txt paths are not, so the slug
keeps the case the URL wrote (`KEEP_CASE`).
Written from live career sites on 2026-09-29 (`docs/plan-hosts/workday.md`).
The listing carries no description, so `detail` reads each role's own JSON.
"""
from __future__ import annotations
import html
import json
import logging
import re
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
from typing import Any
from desk.sources import strip_html
from ._contract import Ask, Fields, Place, Reads
from ._shared import Get, Page, Row, only, parse_dt
log = logging.getLogger(__name__)
NAME = "workday"
LABEL = "Workday"
KEEP_CASE = True
READS = Reads(
scope="board", listing="paged", page_size=20, ceiling=2000, text="detail",
complete="stated", places="many",
fields=Fields(posted="trusted", remote="stated", country="stated", employment="stated"),
robots="read: robots.txt allows /<Site>/ (checked 2026-09-29)",
)
#: One group for `<tenant>.<wdN>` and one for the site, which discovery joins
#: into the slug with "/". A locale segment (`/en-US/`, `/de-DE/`) may come
#: between; it is matched case-sensitively, and a bare `/en-US` that is no
#: site at all is refused, so a site is never mistaken for a locale or the
#: other way round. `wday/` is the API path, read by the second pattern. The
#: tenant is lower case only: a slug with capitals in it is no slug.
_TENANT = r"(?-i:[a-z0-9-]+)"
_LOCALE = r"(?-i:[a-z]{2}-[A-Z]{2})"
PATTERNS = (
rf"(?<![A-Za-z0-9.-])({_TENANT}\.wd\d+)\.myworkdayjobs\.com/(?:{_LOCALE}/)?"
rf"(?!wday/)(?!{_LOCALE}(?![A-Za-z0-9_-]))([A-Za-z0-9_-]+)",
rf"(?<![A-Za-z0-9.-])({_TENANT}\.wd\d+)\.myworkdayjobs\.com/wday/cxs/{_TENANT}/"
r"([A-Za-z0-9_-]+)",
)
#: The page size asked for, which is also the only one the host serves: 21 or
#: more answers 400 on every tenant tried.
PAGE_SIZE = 20
#: Matched whole, so a trailing newline is no slug.
_SLUG = re.compile(r"([a-z0-9-]+)\.(wd\d+)/([A-Za-z0-9_-]+)")
#: The path of one role on its site, `externalPath` in the listing
#: (`/job/...`): a path, and nothing that adds a query or a fragment.
_ROLE_PATH = re.compile(r"/[^\s?#]+")
def _parts(slug: str) -> tuple[str, str, str] | None:
"""`(tenant, data centre, site)`, or None for a slug that is none."""
match = _SLUG.fullmatch(slug)
return match.groups() if match else None # type: ignore[return-value]
def _host(slug: str) -> str:
tenant, dc, _site = _parts(slug) or ("", "", "")
return f"{tenant}.{dc}.myworkdayjobs.com"
def slug_ok(slug: str) -> bool:
return _parts(slug) is not None
def allowed(slug: str) -> Callable[[str], bool]:
"""Only the tenant's own host. A slug that is none admits nothing, rather
than a host the company does not own."""
return only(_host(slug)) if _parts(slug) else (lambda host: False)
def careers_url(slug: str) -> str:
return f"https://{_host(slug)}/{_parts(slug)[2]}" # type: ignore[index]
def page(get: Get, slug: str, cursor: Any, ask: Ask = Ask()) -> Page:
"""`cursor` is `(offset, total)`. `total` is read on the first page only:
on the later ones it is 0 on most tenants and the real figure on a few,
so it is carried. An offset at or past the end does not answer an empty
list but the first page again, so the read stops on `offset >= total`
rather than on an empty page."""
tenant, _dc, site = _parts(slug) # type: ignore[misc]
offset, total = cursor or (0, None)
data = json.loads(get(
f"https://{_host(slug)}/wday/cxs/{tenant}/{site}/jobs", method="POST",
payload={"appliedFacets": {}, "limit": PAGE_SIZE, "offset": offset, "searchText": ""}))
if cursor is None:
stated = data.get("total")
total = stated if isinstance(stated, int) and not isinstance(stated, bool) else None
postings = data.get("jobPostings") or []
# Every posting is counted, a path-less one (LEGO lists one that has only
# `bulletFields`) by its position, so the parser dropping it does not
# leave the board short of its total.
results = [{"id": _posting_id(p, offset + i)} for i, p in enumerate(postings)]
following = offset + len(postings)
more = bool(postings) and (total is None or following < total)
return data, results, total, (following, total) if more else None
def _posting_id(posting: dict[str, Any], position: int) -> str:
return str(posting.get("externalPath") or "".join(posting.get("bulletFields") or [])
or f"#{position}")
def _posted(text: str) -> datetime | None:
"""The day of "Posted Today", "Posted Yesterday" and "Posted 5 Days Ago"
at midnight UTC; None for "Posted 30+ Days Ago", which says only that it
is older, and for a text in another language. Workday counts the days in
its own time zone, so the day can be one off; `detail` states the date
itself and replaces this one."""
match = re.fullmatch(r"Posted (?:(Today)|(Yesterday)|(\d+) Days? Ago)", (text or "").strip())
if not match:
return None
days = 0 if match.group(1) else 1 if match.group(2) else int(match.group(3))
return _today() - timedelta(days=days)
def _today() -> datetime:
return datetime.now(UTC).replace(hour=0, minute=0, second=0, microsecond=0)
#: `remoteType` -> `store._remote`'s words. Only some tenants send it, and
#: each words it its own way (Zendesk's "Fully Flexible", Axis' "On-Site"); a
#: word not listed, a bare "No" among them, says nothing and stays unknown.
_REMOTE = {"remote": "remote", "fully flexible": "remote", "hybrid": "hybrid",
"in office": "onsite", "on-site": "onsite", "onsite": "onsite"}
def _requisition(posting: dict[str, Any], path: str) -> str:
"""The requisition id, which `bulletFields` lead with, if the path ends in
it (`..._R-059566`, and `..._R-059566-2` for a repost of it). Where a
tenant puts something else first, a place, the path is the id."""
first = next(iter(posting.get("bulletFields") or []), None)
name = path.rsplit("/", 1)[-1]
return first if isinstance(first, str) and re.fullmatch(
rf".*_{re.escape(first)}(?:-\d+)?", name) else ""
def _remote(value: Any) -> str | None:
return _REMOTE.get(str(value or "").strip().lower())
#: `timeType` -> the app's employment words.
_EMPLOYMENT = {"full time": "full_time", "part time": "part_time"}
#: What `locationsText` says of a role at several places: "2 Locations". The
#: places arrive with the role's own read.
_COUNT = re.compile(r"\d+ locations?", re.I)
def _place(text: Any, remote: str | None) -> Place | None:
"""A place as Workday writes it, or None for none. Some tenants write
"Country - City" ("Denmark - Copenhagen", "USA - Texas - Austin"), which
is turned round to the order the rest of the app reads, "Copenhagen,
Denmark"; a place that starts with a work-mode word ("Remote - Germany")
is left as it is. A place is remote or an office as far as the role's
`remoteType` says."""
text = " ".join(str(text or "").split())
if not text or _COUNT.fullmatch(text):
return None
parts = [part.strip() for part in text.split(" - ")]
if len(parts) > 1 and "," not in text and all(parts) \
and not parts[0].lower().startswith(("remote", "hybrid", "on-site", "onsite")):
text = ", ".join(reversed(parts))
return {"text": text, "remote": {"remote": True, "hybrid": False, "onsite": False}.get(
remote or "")}
def rows(decoded: dict[str, Any], slug: str) -> list[Row]:
"""One page of `.../wday/cxs/<tenant>/<Site>/jobs` -> `{"total",
"jobPostings": [...], "facets": [...]}`. A posting has `title`,
`externalPath` (`/job/<place>/<title>_<requisition id>`), `locationsText`
(a place, or "2 Locations"), `postedOn` (relative text) and
`bulletFields`, which lead with the requisition id, and on some tenants
`remoteType`. No description, no date and no country: `detail` has
those, and the places of a role that "2 Locations" hides. The id is the requisition id where the path carries it, and the
path where not; a posting with no title or no path is skipped."""
out = []
for p in decoded.get("jobPostings") or []:
title = (p.get("title") or "").strip()
path = (p.get("externalPath") or "").strip()
if not title or not _ROLE_PATH.fullmatch(path):
continue
remote = _remote(p.get("remoteType"))
place = _place(p.get("locationsText"), remote)
out.append({
"source_id": _requisition(p, path) or path,
"title": title,
"places": [place] if place else [],
"location": place["text"] if place else "",
"url": f"https://{_host(slug)}/{_parts(slug)[2]}{path}", # type: ignore[index]
"posted": _posted(p.get("postedOn") or ""),
"department": "",
"description": "",
"remote": remote,
"salary_text": "", # no field for pay, only the description's text
})
return out
def detail(get: Get, slug: str, row: Row) -> dict[str, Any]:
"""The role's own JSON, `.../wday/cxs/<tenant>/<Site><externalPath>`. The
path is taken back off the row's URL, which was built from it. Pay is in
the description text when it is anywhere: there is no field for it on
any tenant. `startDate` is the posting date (it matched the "Posted N
Days Ago" text in every sample), not a start of employment."""
tenant, _dc, site = _parts(slug) # type: ignore[misc]
prefix = f"https://{_host(slug)}/{site}"
path = str(row.get("url") or "").removeprefix(prefix)
if path == row.get("url") or not _ROLE_PATH.fullmatch(path) or ".." in path.split("/"):
raise ValueError(f"{row.get('url')!r} is not a role of {slug}")
info = json.loads(get(f"https://{_host(slug)}/wday/cxs/{tenant}/{site}{path}"))
posting = info.get("jobPostingInfo")
if not isinstance(posting, dict):
raise ValueError("not a Workday role: no jobPostingInfo")
out: dict[str, Any] = {}
if description := " ".join(html.unescape(strip_html(posting.get("jobDescription") or ""))
.split()):
out["description"] = description
remote = _remote(posting.get("remoteType"))
if places := _places(posting, remote):
out["places"] = places
out["location"] = "; ".join(p["text"] for p in places)
if len(places) == 1 and (code := _country_code(posting)):
out["country"] = code
if employment := _EMPLOYMENT.get(str(posting.get("timeType") or "").strip().lower()):
out["employment"] = employment
if posted := parse_dt(posting.get("startDate")):
out["posted"] = posted
if remote:
out["remote"] = remote
return out
def _country_code(posting: dict[str, Any]) -> str | None:
"""The role's country as an ISO code, from the requisition's location. The
code belongs to the main location only, so it is used for a role with one
place."""
country = (posting.get("jobRequisitionLocation") or {}).get("country") or {}
code = str(country.get("alpha2Code") or "").strip().upper()
return code if len(code) == 2 else None
def _places(posting: dict[str, Any], remote: str | None) -> list[Place]:
"""The main location and the additional ones, each once, which replace the
listing's "2 Locations". A single location that does not name its country
(LEGO's "Billund") gets it from the role's `country`."""
found: list[Place] = []
for name in [posting.get("location"), *(posting.get("additionalLocations") or [])]:
place = _place(name, remote)
if place and place["text"] not in (p["text"] for p in found):
found.append(place)
country = str((posting.get("country") or {}).get("descriptor") or "").strip()
if len(found) == 1 and country and country.lower() not in found[0]["text"].lower():
found[0]["text"] += f", {country}"
return found