Read a Phenom role's description from the page state when the page has no JobPosting, and fail a page with neither

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet 5.5 committed 2026-09-29 20:10:52 +02:00
1 parent 8f0db38393
commit cf182ad921
3 files changed
+77 -17

No files matched your search

+46 -14
View File
@@ -169,15 +169,14 @@ def rows(search: dict[str, Any], slug: str) -> list[Row]:
_JSON_LD = re.compile(r"<script[^>]+application/ld\+json[^>]*>(.*?)</script>", 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 (`&lt;p&gt;`
and `&amp;` 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] = {}
#: Where a page assigns its state, and the words its `checkRemote` says that
#: `store._remote` reads (King's pages say "On-site"; no other was seen).
_STATE = "phApp.ddo = "
_REMOTE = {"remote": "remote", "hybrid": "hybrid", "on-site": "onsite", "onsite": "onsite"}
def _job_posting(body: str) -> dict[str, Any]:
"""The `JobPosting` among a page's JSON-LD blocks, or {}."""
for block in _JSON_LD.findall(body):
try:
found = json.loads(block)
@@ -185,13 +184,46 @@ def detail(get: Get, slug: str, row: Row) -> dict[str, Any]:
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
return candidate
return {}
def _page_job(body: str) -> dict[str, Any]:
"""The role as the page's own state holds it, `phApp.ddo.jobDetail.data.job`,
or {}. King's pages of roles posted the same day had no `JobPosting`, and
this had the full description. Only that one object is read: the state
around it holds the site's session values, which nothing here uses."""
start = body.find(_STATE)
if start < 0:
return {}
try:
state, _end = json.JSONDecoder().raw_decode(body, start + len(_STATE))
job = state["jobDetail"]["data"]["job"]
except (ValueError, KeyError, TypeError):
return {}
return job if isinstance(job, dict) else {}
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 (`&lt;p&gt;`
and `&amp;` inside), so it is unescaped, stripped and unescaped again; or,
where the page has none, the page state's own `description`, which is
plain HTML. A page with neither raises, so the role is asked again on a
later pull instead of counting as read with no text. `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. King's page state says `checkRemote`."""
body = get(row["url"], headers={"Accept": "text/html"}).decode("utf-8", "replace")
posting, job = _job_posting(body), _page_job(body)
out: dict[str, Any] = {}
if description := _plain(html.unescape(_text(posting.get("description")))):
if description := (_plain(html.unescape(_text(posting.get("description"))))
or _plain(job.get("description"))):
out["description"] = description
else:
raise ValueError("no description on the role's page")
if posted := parse_dt(posting.get("datePosted")):
out["posted"] = posted
if remote := _REMOTE.get(_text(job.get("checkRemote")).lower()):
out["remote"] = remote
return out
+6
View File
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html lang="en"><head>
<title>Principal Economy Designer | New Games in Barcelona, Spain | Games Design & Production at King</title>
<script type="application/ld+json">{"@context": "https://schema.org","@type": "WebPage","inLanguage": "en_us","name": "job","url": "https://careers.king.com/us/en/job/R028168/Principal-Economy-Designer-New-Games","datePublished": "2024-08-14","dateModified": "2024-08-14"}</script>
<script>phApp.ddo = {"jobDetail": {"status": "success", "data": {"job": {"title": "Principal Economy Designer | New Games", "jobSeqNo": "ACMKDSUSR028168EXTERNALENUS", "jobId": "R028168", "postedDate": "2026-09-29T00:00:00.000+0000", "dateCreated": "2026-09-29T09:59:51.253+0000", "location": "Barcelona, Spain", "category": "Games Design & Production", "checkRemote": "On-site", "timeType": "Full time", "description": "<p style=\"text-align:left\"><b>Craft:</b></p>Games Design &amp; Production<p style=\"text-align:inherit\"></p><p style=\"text-align:left\"><b>Job Description:</b></p><div><p><b><span>Principal Economy and System Designer</span></b><span> </span></p></div><div><p><b><span>Unannounced Merge 2 Game</span></b><span> </span></p><p></p></div><div><p><span><span>Join our team and help shape an unannounced Merge 2 game from the ground up. We are looking for a Principal Economy and System Designer who can turn a compelling merge fantasy into a clear, generous, and sustainable player journey. You will own the economic and systemic foundations that connect core merging, progression, events, </span><span>monetisation</span><span>, and long-term engagement.</span></span><span> </span></p><p></p></div><div><p><span><span>This is a senior, hands-on design role for someone with proven </span><span>economy</span><span> design experience in successful merge games. You will partner with creative leadership and a multidisciplinary team to build an economy that feels intuitive to players, performs against product goals, and can evolve confidently through development and live operation.</span></span><span> </span></p><p></p></div><div><h2><b><span>Your role within the Kingdom</span></b></h2></div><div><p><span><span>You will be the principal owner and champion of economy design for the game, </span><span>setting</span><span> a high bar for systemic clarity, player value, and commercial sustainability. Specifically, you will:</span></span><span> </span></p></div><div><ul><li><p><span><span>Own the design, modelling, balancing, and ongoing health of the game economy across the full player lifecycle, from first-session experience through long-term progression and live events.</span></span><span> </span></p></li></ul></div><div><ul><li><p><span><span>Define the Merge 2 economy: merge chains, generators, energy and action loops, currencies, rewards, inventories, orders, unlocks, progression gates, and the relationships between them.</span></span><span> </span></p></li></ul></div><div><ul><li><p><span><span>Design progression systems and content pacing that create clear short-, mid-, and long-term goals while preserving meaningful player choice and satisfying merge moments.</span></span><span> </span></p></li></ul></div><div><ul><li><p><span><span>Build and </span><span>maintain</span><span> economy models, simulations, and tools that forecast progression, currency flows, resource ..."}}}}; phApp.sessionParams = {"pxSegmentState":"stranger"};</script>
</head><body></body></html>
+25 -3
View File
@@ -198,11 +198,33 @@ def test_detail_finds_the_job_posting_among_other_blocks_and_takes_its_date() ->
assert got["posted"].isoformat() == "2026-09-08T00:00:00+00:00"
def test_detail_of_a_page_without_a_posting_has_nothing_to_read() -> None:
def test_detail_falls_back_to_the_page_state_where_there_is_no_job_posting() -> None:
"""King's pages of roles posted that day had no `JobPosting` block, only a
`WebPage` one, and the role in the state the page assigns to `phApp.ddo`."""
row = _rows()[0]
got = phenom.detail(_get_of("phenom-detail-3.html", []), SLUG, row)
assert got["description"].startswith("Craft: Games Design & Production Job Description:")
assert "<" not in got["description"] and "&amp;" not in got["description"]
assert got["remote"] == "onsite"
assert "posted" not in got and set(got) <= set(ats.DETAIL_FIELDS)
def test_detail_of_a_page_with_no_description_fails_so_that_it_is_asked_again() -> None:
def get(url: str, **kwargs: Any) -> bytes:
return (b'<html><script type="application/ld+json">{"@type": "BreadcrumbList"}</script>'
b'<script type="application/ld+json">{broken</script></html>')
assert phenom.detail(get, SLUG, {"url": "https://careers.king.com/us/en/job/1"}) == {}
b'<script type="application/ld+json">{broken</script>'
b'<script>phApp.ddo = {"jobDetail": {"data": {"job": {"title": "x"}}}};</script></html>')
with pytest.raises(ValueError, match="no description"):
phenom.detail(get, SLUG, {"url": "https://careers.king.com/us/en/job/1"})
@pytest.mark.parametrize("state", ["", "phApp.ddo = {broken", 'phApp.ddo = {"jobDetail": []};',
'phApp.ddo = {"siteConfig": {}};'])
def test_a_page_state_that_is_not_a_role_is_no_description(state: str) -> None:
def get(url: str, **kwargs: Any) -> bytes:
return f"<html><script>{state}</script></html>".encode()
with pytest.raises(ValueError, match="no description"):
phenom.detail(get, SLUG, {"url": "https://careers.king.com/us/en/job/1"})
# ----------------------------------------------------------- slug and URLs