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>
344 lines
15 KiB
Python
344 lines
15 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.
|
|
The listing carries no description, so `detail` reads each role's own JSON.
|
|
|
|
Countries and remote are filtered on the server by the tenant's own facets
|
|
(`Filters(country="ids", remote="ids")`): `appliedFacets` takes
|
|
`{<facetParameter>: [<id>, ...]}`, ids within one facet are a union, and two
|
|
facets are an intersection, which is why the runner asks for remote in a
|
|
series of its own. Each tenant names its facets its own way (LEGO's
|
|
`Location` lists countries, others nest `locationCountry` under
|
|
`locationMainGroup`), so `facets` reads them off the first page and picks the
|
|
one whose values are countries. A host id is `<facetParameter>=<id>`. LEGO
|
|
answered 97 of 455 for Denmark on 2026-09-30; a role at several places is
|
|
kept when one of them is in the country.
|
|
|
|
A fetch term goes as `searchText` in the body, one a request
|
|
(`Filters(query="one")`); it is an AND with `appliedFacets` (survey,
|
|
2026-09-30: LEGO's `engineer` answered 106, 45 of them in Denmark).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import re
|
|
from collections.abc import Callable
|
|
from datetime import UTC, datetime, timedelta
|
|
from typing import Any
|
|
|
|
|
|
from ._contract import Ask, Fields, Filters, Place, Reads
|
|
from ._countries import code_of
|
|
from ._shared import Get, Page, Row, add_place, html_text, only, parse_dt
|
|
|
|
NAME = "workday"
|
|
LABEL = "Workday"
|
|
KEEP_CASE = True
|
|
|
|
READS = Reads(
|
|
scope="board", listing="paged", page_size=20, ceiling=2000, text="detail",
|
|
complete="stated", places="many", filters=Filters(country="ids", remote="ids", query="one"),
|
|
fields=Fields(posted="trusted", remote="stated", employment="stated"),
|
|
robots=("read: robots.txt allows /<Site>/ and disallows /refreshFacet/ and has no rule "
|
|
"on /wday/cxs/<tenant>/<site>/, the listing's POST .../jobs and each role's "
|
|
"JSON (zendesk.wd1, lego.wd103, saxobank.wd3, checked 2026-09-30)"),
|
|
)
|
|
|
|
#: 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": _applied(ask), "limit": PAGE_SIZE, "offset": offset,
|
|
"searchText": ask.query}))
|
|
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 _applied(ask: Ask) -> dict[str, list[str]]:
|
|
"""`appliedFacets` for the host ids `ask` carries, `<facetParameter>=<id>`
|
|
each, grouped by facet."""
|
|
out: dict[str, list[str]] = {}
|
|
for value in (*ask.countries, *ask.remote_ids):
|
|
facet, sep, value_id = value.partition("=")
|
|
if sep and facet and value_id:
|
|
out.setdefault(facet, []).append(value_id)
|
|
return out
|
|
|
|
|
|
#: A facet whose values are countries: at least this share of them name one.
|
|
_COUNTRY_SHARE = 0.8
|
|
|
|
|
|
def _facet_lists(facets: Any) -> list[tuple[str, list[dict[str, Any]]]]:
|
|
"""`(facetParameter, values)` of every facet of an answer, the facets nested
|
|
in a group (`locationMainGroup` holds `locationCountry` on some tenants)
|
|
included."""
|
|
out: list[tuple[str, list[dict[str, Any]]]] = []
|
|
for facet in facets if isinstance(facets, list) else []:
|
|
if not isinstance(facet, dict):
|
|
continue
|
|
values = [v for v in facet.get("values") or [] if isinstance(v, dict)]
|
|
nested = [v for v in values if "values" in v and "facetParameter" in v]
|
|
out += _facet_lists(nested)
|
|
plain = [v for v in values if v not in nested]
|
|
if plain and str(facet.get("facetParameter") or ""):
|
|
out.append((str(facet["facetParameter"]), plain))
|
|
return out
|
|
|
|
|
|
def facets(get: Get, slug: str) -> dict[str, dict[str, str]]:
|
|
"""The tenant's host ids, read off one page of one role: `country` maps
|
|
an ISO code to `<facetParameter>=<id>` in the facet whose values are
|
|
countries (most of them, `_COUNTRY_SHARE`; the one with most countries
|
|
when two are), and `remote` maps each facet value that `_REMOTE_FACET` names as
|
|
remote ("Remote", "Fully Flexible"), in whatever facet, to its id. A
|
|
tenant with neither states no such dimension, and the runner then does
|
|
not filter on it."""
|
|
tenant, _dc, site = _parts(slug) # type: ignore[misc]
|
|
data = json.loads(get(
|
|
f"https://{_host(slug)}/wday/cxs/{tenant}/{site}/jobs", method="POST",
|
|
payload={"appliedFacets": {}, "limit": 1, "offset": 0, "searchText": ""}))
|
|
country: dict[str, str] = {}
|
|
remote: dict[str, str] = {}
|
|
for name, values in _facet_lists(data.get("facets")):
|
|
found = {code: f"{name}={v['id']}" for v in values
|
|
if v.get("id") and (code := code_of(str(v.get("descriptor") or "")))}
|
|
if len(found) >= _COUNTRY_SHARE * len(values) and len(found) > len(country):
|
|
country = found
|
|
for v in values:
|
|
word = " ".join(str(v.get("descriptor") or "").split())
|
|
if v.get("id") and word.lower() in _REMOTE_FACET:
|
|
remote[word.lower()] = f"{name}={v['id']}"
|
|
out: dict[str, dict[str, str]] = {}
|
|
if country:
|
|
out["country"] = country
|
|
if remote:
|
|
out["remote"] = remote
|
|
return out
|
|
|
|
|
|
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)
|
|
|
|
|
|
#: The `remoteType` words a facet names that mean remote, which the `remote`
|
|
#: filter looks for; the row keeps the host's word whatever it is (only some
|
|
#: tenants send it, each in its own way: Zendesk's "Fully Flexible", Axis'
|
|
#: "On-Site").
|
|
_REMOTE_FACET = ("remote", "fully flexible")
|
|
|
|
#: The words that put a role's places in an office, for their `remote` flag.
|
|
_OFFICE = ("hybrid", "in office", "on-site", "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:
|
|
"""The host's `remoteType`, as given."""
|
|
return str(value or "").strip() or None
|
|
|
|
|
|
#: 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))
|
|
word = (remote or "").lower()
|
|
return {"text": text, "remote": True if word in _REMOTE_FACET
|
|
else False if word in _OFFICE else None}
|
|
|
|
|
|
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 := html_text(posting.get("jobDescription")):
|
|
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 employment := str(posting.get("timeType") or "").strip():
|
|
out["employment"] = employment
|
|
if posted := parse_dt(posting.get("startDate")):
|
|
out["posted"] = posted
|
|
if remote:
|
|
out["remote"] = remote
|
|
return out
|
|
|
|
|
|
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 [])]:
|
|
if place := _place(name, remote):
|
|
add_place(found, 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
|