diff --git a/plugins/atshosts/phenom.py b/plugins/atshosts/phenom.py new file mode 100644 index 0000000..7b0512a --- /dev/null +++ b/plugins/atshosts/phenom.py @@ -0,0 +1,197 @@ +"""Phenom: `phenom://`, the career site a company runs +on its own domain, at the locale root it uses: `phenom:careers.king.com/us/en`, +`phenom:www.careers.philips.com/global/en`. A JSON search that pages by offset +and states its total. + +The listing is the `POST /widgets` call the site's own search page makes. It +answered without a cookie, an `Origin` header, a `pageId` or the site's +`refNum`, so the body carries none of them: only the locale (`lang`, +`country`, both read off the slug's path) and the paging. Nothing is taken +from the page's script. Written from live sites on 2026-09-29 (King, Just Eat +Takeaway, Philips); jobhunt-hq did not read Phenom. +""" + +from __future__ import annotations + +import html +import json +import re +from collections.abc import Callable +from typing import Any + +from desk.sources import strip_html + +from ._shared import Get, Page, Row, only, parse_dt + +NAME = "phenom" +LABEL = "Phenom" +PATTERNS = ( + # A link to the site's search page, the one URL of a Phenom site that carries + # both the host and the locale root and is named the same on every one. + r"https?://([a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z][a-z0-9-]*)/([a-z]{2,8})/([a-z]{2})/search-results", + # No slug: a page that loads Phenom's own assets, on a site whose locale + # root discovery has not seen. The host is known, the board is not. + r"phenompeople\.com|phenom\.com/careers", +) + +#: The page size asked for. 100 is what the site's own search sends; `size` +#: 200 was answered in full by Just Eat Takeaway and 500 by Philips (of 865), +#: but a page is 340 KB at 100 roles already. +PAGE_SIZE = 100 + +#: A DNS name with a dot and a letter first in its last label, so an address +#: (`127.0.0.1`) or a single word (`localhost`) never names a site the fetch +#: could be pointed at; `ats._get` still refuses local names and every host +#: but this one, redirects included. Then the locale root: `country/lang`, +#: which every Phenom site read so far writes as `global/en`, `na/en`, `us/en`. +_SLUG = re.compile(r"[a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z][a-z0-9-]*/[a-z]{2,8}/[a-z]{2}") + + +def _parts(slug: str) -> tuple[str, str, str]: + """`(host, country, lang)` of a slug that passed `slug_ok`.""" + host, country, lang = slug.split("/") + return host, country, lang + + +def slug_ok(slug: str) -> bool: + return bool(_SLUG.fullmatch(slug)) + + +def allowed(slug: str) -> Callable[[str], bool]: + return only(_parts(slug)[0]) + + +def _root(slug: str) -> str: + host, country, lang = _parts(slug) + return f"https://{host}/{country}/{lang}" + + +def careers_url(slug: str) -> str: + return f"{_root(slug)}/search-results" + + +def robots_page(slug: str) -> str: + return careers_url(slug) + + +def _body(slug: str, offset: int) -> dict[str, Any]: + """What the site's search page sends for a listing of every role, newest + first, less the parts that only tell the page what to draw. `lang` is + `en_global` for `/global/en` and `en_us` for `/us/en`, the site's own + spelling on the three sites read.""" + _host, country, lang = _parts(slug) + return { + "lang": f"{lang}_{country}", "deviceType": "desktop", "country": country, + "pageName": "search-results", "ddoKey": "refineSearch", "sortBy": "", + "subsearch": "", "from": offset, "jobs": True, "counts": True, "all_fetch": False, + "pageType": "landingPage", "size": PAGE_SIZE, "clearAll": False, + "jdsource": "facets", "isSliderEnable": False, "siteType": "external", + "location": "", "keywords": "", "global": True, "selected_fields": {}, + "sort": {"order": "desc", "field": "postedDate"}, "locationData": {}, + } + + +def _key(job: dict[str, Any]) -> str: + """The role's id on the board: `jobSeqNo`, which carries the site and the + language and is the one of the three ids (`jobSeqNo`, `jobId`, `reqId`) + that the site's job page takes on every site read. `reqId` is not unique + across languages.""" + return str(job.get("jobSeqNo") or job.get("jobId") or job.get("reqId") or "").strip() + + +def page(get: Get, slug: str, cursor: Any) -> Page: + offset = int(cursor or 0) + host = _parts(slug)[0] + data = json.loads(get(f"https://{host}/widgets", method="POST", + payload=_body(slug, offset))) + search = data.get("refineSearch") + if not isinstance(search, dict) or search.get("status", 200) != 200: + raise ValueError("not a Phenom search answer: no refineSearch") + jobs = (search.get("data") or {}).get("jobs") or [] + results = [{"id": _key(job)} for job in jobs] + return search, results, search.get("totalHits"), offset + len(jobs) if jobs else None + + +def parse(body: bytes, slug: str) -> list[Row]: + return rows(json.loads(body).get("refineSearch") or {}, slug) + + +def _text(value: Any) -> str: + return value.strip() if isinstance(value, str) else "" + + +def _plain(value: Any) -> str: + return html.unescape(strip_html(_text(value))).replace("\xa0", " ").strip() + + +def _slug_of(title: str) -> str: + """The decorative last part of a role's URL, its title with runs of + anything but letters and digits as one dash; it matches the site's own + (checked on all 32 roles of King's sitemap). The page is found by the id.""" + return re.sub(r"[^A-Za-z0-9]+", "-", title).strip("-") + + +def rows(search: dict[str, Any], slug: str) -> list[Row]: + """The roles of one page, `refineSearch.data.jobs`. A role has the title, + `jobSeqNo`, `postedDate` (a date at midnight), `category`, the locations + as `multi_location` (a list, one per place) beside `location` (the first), + and `descriptionTeaser`, the first paragraph of the text; the full text is + on the role's page, see `detail`. `applyUrl` points at the apply system + (Workday for Just Eat Takeaway and Philips), so the role's URL is its page + on the site. No remote flag and no pay are in the list.""" + out = [] + for job in search.get("data", {}).get("jobs") or []: + key = _key(job) + title = _text(job.get("title")) + if not title or not key: + continue + places: list[str] = [] + for place in (*(job.get("multi_location") or []), job.get("location")): + if isinstance(place, str) and place.strip() and place.strip() not in places: + places.append(place.strip()) + tail = _slug_of(title) + out.append({ + "source_id": key, + "title": title, + "location": "; ".join(places), + "url": f"{_root(slug)}/job/{key}" + (f"/{tail}" if tail else ""), + "posted": parse_dt(job.get("postedDate")), + "department": _text(job.get("category")), + "description": _plain(job.get("descriptionTeaser")), + "remote": None, # the list does not say + "salary_text": "", # nor does it state pay + }) + return out + + +#: The JSON-LD blocks of a page; a Phenom job page has one `JobPosting` and, +#: on Philips's, a `BreadcrumbList` and more. +_JSON_LD = re.compile(r"]+application/ld\+json[^>]*>(.*?)", re.S | re.I) + + +def detail(get: Get, slug: str, row: Row) -> dict[str, Any]: + """The full description from the role's page: the `JobPosting` in its + JSON-LD, whose `description` is HTML with its entities escaped (`<p>` + and `&` inside), so it is unescaped, stripped and unescaped again. + `datePosted` is taken as `posted`: it can be earlier than the list's + `postedDate` (Philips's list said the day of the read for a role whose page + said 2026-09-08), and a role keeps the earliest date it ever had.""" + body = get(row["url"], headers={"Accept": "text/html"}).decode("utf-8", "replace") + posting: dict[str, Any] = {} + for block in _JSON_LD.findall(body): + try: + found = json.loads(block) + except ValueError: + continue + for candidate in found if isinstance(found, list) else [found]: + if isinstance(candidate, dict) and candidate.get("@type") == "JobPosting": + posting = candidate + break + if posting: + break + out: dict[str, Any] = {} + if description := _plain(html.unescape(_text(posting.get("description")))): + out["description"] = description + if posted := parse_dt(posting.get("datePosted")): + out["posted"] = posted + return out diff --git a/tests/fixtures/ats/phenom-detail-2.html b/tests/fixtures/ats/phenom-detail-2.html new file mode 100644 index 0000000..0c2b862 --- /dev/null +++ b/tests/fixtures/ats/phenom-detail-2.html @@ -0,0 +1,7 @@ + + +Zone Business Leader Imaging Nordics job in Denmark - Remote Based, Denmark, Denmark | Sales jobs at Philips + + + + diff --git a/tests/fixtures/ats/phenom-detail.html b/tests/fixtures/ats/phenom-detail.html new file mode 100644 index 0000000..7ad025c --- /dev/null +++ b/tests/fixtures/ats/phenom-detail.html @@ -0,0 +1,6 @@ + + +Product Analyst in Stockholm, Stockholm County, Sweden | Data, Analytics & Strategy at King + + + diff --git a/tests/fixtures/ats/phenom.json b/tests/fixtures/ats/phenom.json new file mode 100644 index 0000000..73887e0 --- /dev/null +++ b/tests/fixtures/ats/phenom.json @@ -0,0 +1,322 @@ +{ + "refineSearch": { + "status": 200, + "hits": 5, + "totalHits": 32, + "data": { + "jobs": [ + { + "type": "Regular", + "descriptionTeaser": "Become part of our team and help shape the economic and systemic foundations of an unannounced Merge 2 game. Take ownership of the game\u2019s economy, ensuring a clear, sustainable player journey. Ideal for a senior designer with proven ...", + "state": "", + "siteType": "external", + "multi_category": [ + "Games Design & Production" + ], + "reqId": "R028168", + "city": "Barcelona", + "latitude": "41.38879", + "multi_location": [ + "Barcelona, Spain", + "London, London, United Kingdom", + "Stockholm, Stockholm County, Sweden" + ], + "address": "Carrer Ciutat de Granada, 150, Floor 16th Floor, 08018 Barcelona, Spain", + "applyUrl": "https://xboxgaming.wd1.myworkdayjobs.com/King_External_Careers/job/Barcelona---King---PG/Principal-Economy-Designer---New-Games_R028168/apply", + "externalApply": false, + "cityState": "Barcelona", + "country": "Spain", + "visibilityType": "External", + "longitude": "2.15899", + "jobId": "R028168", + "locale": "en_US", + "title": "Principal Economy Designer | New Games", + "jobSeqNo": "ACMKDSUSR028168EXTERNALENUS", + "postedDate": "2026-09-29T00:00:00.000+0000", + "dateCreated": "2026-09-29T09:59:51.253+0000", + "cityStateCountry": "Barcelona, Spain", + "jobVisibility": [ + "external" + ], + "location": "Barcelona, Spain", + "category": "Games Design & Production", + "isMultiLocation": true, + "multi_location_array": [ + { + "latlong": { + "lon": 2.15899, + "lat": 41.38879 + }, + "location": "Barcelona, Spain" + }, + { + "latlong": { + "lon": -0.12574, + "lat": 51.50853 + }, + "location": "London, London, United Kingdom" + }, + { + "latlong": { + "lon": 18.06871, + "lat": 59.32938 + }, + "location": "Stockholm, Stockholm County, Sweden" + } + ], + "isMultiCategory": false, + "multi_category_array": [ + { + "category": "Games Design & Production" + } + ], + "badge": "" + }, + { + "type": "Regular", + "descriptionTeaser": "Take on the role of Senior Data Visualisation Engineer to develop and maintain dashboards and analytical tools for business intelligence. Collaborate with cross-functional teams to deliver insightful visualisations and support high-volume ...", + "state": "Stockholm County", + "siteType": "external", + "multi_category": [ + "Technology & Development" + ], + "reqId": "R027656", + "city": "Stockholm", + "latitude": "59.32938", + "multi_location": [ + "Stockholm, Stockholm County, Sweden" + ], + "address": "Malmskillnadsgatan 19, 111 57 Stockholm, Sweden", + "applyUrl": "https://xboxgaming.wd1.myworkdayjobs.com/King_External_Careers/job/Stockholm---King---Malmskillnadsgatan/Senior-Data-Visualisation-Engineer--12mth-FTC-_R027656-1/apply", + "externalApply": false, + "cityState": "Stockholm, Stockholm County", + "country": "Sweden", + "visibilityType": "External", + "longitude": "18.06871", + "jobId": "R027656", + "locale": "en_US", + "title": "Senior Data Visualisation Engineer (12mth FTC)", + "jobSeqNo": "ACMKDSUSR027656EXTERNALENUS", + "postedDate": "2026-09-28T00:00:00.000+0000", + "dateCreated": "2026-06-15T17:02:06.245+0000", + "cityStateCountry": "Stockholm, Stockholm County, Sweden", + "jobVisibility": [ + "external" + ], + "location": "Stockholm, Stockholm County, Sweden", + "category": "Technology & Development", + "isMultiLocation": true, + "multi_location_array": [ + { + "latlong": { + "lon": 18.06871, + "lat": 59.32938 + }, + "location": "Stockholm, Stockholm County, Sweden" + } + ], + "isMultiCategory": false, + "multi_category_array": [ + { + "category": "Technology & Development" + } + ], + "badge": "" + }, + { + "type": "Regular", + "descriptionTeaser": "We are looking for a Technical Artist to shape the visual direction of new games, collaborating with artists, designers, and engineers to deliver polished, in-engine experiences. This senior role focuses on building shaders, materials, and ...", + "state": "London", + "siteType": "external", + "multi_category": [ + "Other" + ], + "reqId": "R028172", + "city": "London", + "latitude": "51.50853", + "multi_location": [ + "London, London, United Kingdom", + "Barcelona, Spain", + "Stockholm, Stockholm County, Sweden" + ], + "address": "The Ampersand Building, 178 Wardour Street, London, London, W1F 8FY, United Kingdom", + "applyUrl": "https://xboxgaming.wd1.myworkdayjobs.com/King_External_Careers/job/London---King---Ampersand/Technical-Artist---New-Games_R028172-1/apply", + "externalApply": false, + "cityState": "London, London", + "country": "United Kingdom", + "visibilityType": "External", + "longitude": "-0.12574", + "jobId": "R028172", + "locale": "en_US", + "title": "Technical Artist | New Games", + "jobSeqNo": "ACMKDSUSR028172EXTERNALENUS", + "postedDate": "2026-09-28T00:00:00.000+0000", + "dateCreated": "2026-09-28T13:01:25.961+0000", + "cityStateCountry": "London, London, United Kingdom", + "jobVisibility": [ + "external" + ], + "location": "London, London, United Kingdom", + "category": "Other", + "isMultiLocation": true, + "multi_location_array": [ + { + "latlong": { + "lon": -0.12574, + "lat": 51.50853 + }, + "location": "London, London, United Kingdom" + }, + { + "latlong": { + "lon": 2.15899, + "lat": 41.38879 + }, + "location": "Barcelona, Spain" + }, + { + "latlong": { + "lon": 18.06871, + "lat": 59.32938 + }, + "location": "Stockholm, Stockholm County, Sweden" + } + ], + "isMultiCategory": false, + "multi_category_array": [ + { + "category": "Other" + } + ], + "badge": "" + }, + { + "type": "Regular", + "descriptionTeaser": "We are currently hiring an Engineering Manager to lead the development and evolution of shared platforms supporting King\u2019s games. Drive high-performing teams, foster innovation, and ensure impactful delivery. Ideal for experienced leaders ...", + "state": "Stockholm County", + "siteType": "external", + "multi_category": [ + "Technology & Development" + ], + "reqId": "R028147", + "city": "Stockholm", + "latitude": "59.32938", + "multi_location": [ + "Stockholm, Stockholm County, Sweden", + "Barcelona, Spain" + ], + "address": "Malmskillnadsgatan 19, 111 57 Stockholm, Sweden", + "applyUrl": "https://xboxgaming.wd1.myworkdayjobs.com/King_External_Careers/job/Stockholm---King---Malmskillnadsgatan/Engineering-Manager---Shared-Tech_R028147/apply", + "externalApply": false, + "cityState": "Stockholm, Stockholm County", + "country": "Sweden", + "visibilityType": "External", + "longitude": "18.06871", + "jobId": "R028147", + "locale": "en_US", + "title": "Engineering Manager | Shared Tech", + "jobSeqNo": "ACMKDSUSR028147EXTERNALENUS", + "postedDate": "2026-09-28T00:00:00.000+0000", + "dateCreated": "2026-09-22T13:01:36.026+0000", + "cityStateCountry": "Stockholm, Stockholm County, Sweden", + "jobVisibility": [ + "external" + ], + "location": "Stockholm, Stockholm County, Sweden", + "category": "Technology & Development", + "isMultiLocation": true, + "multi_location_array": [ + { + "latlong": { + "lon": 18.06871, + "lat": 59.32938 + }, + "location": "Stockholm, Stockholm County, Sweden" + }, + { + "latlong": { + "lon": 2.15899, + "lat": 41.38879 + }, + "location": "Barcelona, Spain" + } + ], + "isMultiCategory": false, + "multi_category_array": [ + { + "category": "Technology & Development" + } + ], + "badge": "" + }, + { + "type": "Regular", + "descriptionTeaser": "Join us as a Principal Game Designer to shape the core gameplay of a new King casual puzzle game. Lead the design and evolution of engaging, challenging levels and interaction systems, collaborating with multidisciplinary teams. Ideal for ...", + "state": "London", + "siteType": "external", + "multi_category": [ + "Other" + ], + "reqId": "R028167", + "city": "London", + "latitude": "51.50853", + "multi_location": [ + "London, London, United Kingdom", + "Barcelona, Spain", + "Stockholm, Stockholm County, Sweden" + ], + "address": "The Ampersand Building, 178 Wardour Street, London, London, W1F 8FY, United Kingdom", + "applyUrl": "https://xboxgaming.wd1.myworkdayjobs.com/King_External_Careers/job/London---King---Ampersand/Principal-Game-Designer---New-Games_R028167/apply", + "externalApply": false, + "cityState": "London, London", + "country": "United Kingdom", + "visibilityType": "External", + "longitude": "-0.12574", + "jobId": "R028167", + "locale": "en_US", + "title": "Principal Game Designer | New Games", + "jobSeqNo": "ACMKDSUSR028167EXTERNALENUS", + "postedDate": "2026-09-25T00:00:00.000+0000", + "dateCreated": "2026-09-25T13:14:11.065+0000", + "cityStateCountry": "London, London, United Kingdom", + "jobVisibility": [ + "external" + ], + "location": "London, London, United Kingdom", + "category": "Other", + "isMultiLocation": true, + "multi_location_array": [ + { + "latlong": { + "lon": -0.12574, + "lat": 51.50853 + }, + "location": "London, London, United Kingdom" + }, + { + "latlong": { + "lon": 2.15899, + "lat": 41.38879 + }, + "location": "Barcelona, Spain" + }, + { + "latlong": { + "lon": 18.06871, + "lat": 59.32938 + }, + "location": "Stockholm, Stockholm County, Sweden" + } + ], + "isMultiCategory": false, + "multi_category_array": [ + { + "category": "Other" + } + ], + "badge": "" + } + ] + } + } +} \ No newline at end of file