Files
jobboard/plugins/readers/eightfold.py
T
WolfandClaude Opus 5.5 c497fe965d Keep a description's headings, bullets and paragraphs, and draw them in the reader
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>
2026-09-30 21:40:12 +02:00

188 lines
8.1 KiB
Python

"""Eightfold: `eightfold:<tenant host>/<domain>`, for example
`eightfold:infineon.eightfold.ai/infineon.com` or, for a career site on the
company's own host, `eightfold:jobs.ericsson.com/ericsson.com`. The public
PCSX search, paged by offset at ten roles a page with the total stated, and a
role's text on its own request.
Written from Ericsson's site on 2026-09-29 (637 roles), with Infineon's and
Microsoft's read the same day in the findings. Unverified on a tenant other
than those three: that the search takes the same parameters and answers with
the same fields.
The `domain` is the tenant's own name for the company, usually the company's
domain, and it is not the host: the site's page carries it as `domain=` in its
links. `/api/apply/v2/jobs` answers 403 "Not authorized for PCSX" on the sites
tried, so it is not used.
The search ignores `num` and answers ten roles a page, so a board costs one
request per ten roles, and `ats.MAX_PAGES` (100) stops a read at 1,000 roles.
The rows are sorted newest first (`sort_by=timestamp`) so that what the cap
keeps is the newest thousand and the pages do not shuffle between two
requests, unlike the default order, which puts hot roles first.
A country is filtered on the server by `location=<country name>`, one a
request (`Filters(country="one")`): Ericsson's "Sweden" answered 154 of 618 on
2026-09-30, a role at several places is kept when one of them matches, and
the review measured Infineon at 163 of 1,288 and Microsoft at 60 of 2,320 for
Denmark and Sweden, which brings both under the cap. A code with no English
name in `_countries` is read unfiltered.
Discovery names Eightfold from an `eightfold.ai` link, and the host and the
domain from one that carries `domain=`.
A fetch term goes as `query=`, one a request (`Filters(query="one")`);
it matches title, text and skills, and is an AND with `location` (survey,
2026-09-30: `software` with Sweden answered 102 of Ericsson's 154 Swedish
roles).
"""
from __future__ import annotations
import json
import re
from collections.abc import Callable
from typing import Any
from urllib.parse import quote
from ._contract import Ask, Fields, Filters, Place, Reads, Row
from ._countries import name_of
from ._shared import Get, Page, add_place, html_text, is_web_url, only, parse_dt, place
READS = Reads(
scope="board", listing="paged", page_size=10, text="detail", complete="stated",
places="many", filters=Filters(country="one", query="one"),
fields=Fields(posted="listed", remote="stated"),
robots=("read: robots.txt disallows / and allows /api/pcsx, which covers "
"/api/pcsx/search and /api/pcsx/position_details (jobs.ericsson.com, "
"checked 2026-09-30)"),
)
NAME = "eightfold"
LABEL = "Eightfold"
PATTERNS = (
# Both parts, from a link to a tenant's site that says its domain.
r"https?://([a-z0-9-]+\.eightfold\.ai)/[^\s\"'<>]*?[?&]domain=([a-z0-9.-]+\.[a-z]{2,})",
# No slug: a link to a tenant's site that does not.
r"[a-z0-9-]+\.eightfold\.ai",
)
#: A whole host name: two labels or more, the last one letters, so neither an
#: address, a bare word nor a port names a site. `ats._get` refuses every host
#: but the tenant's, redirects included.
_NAME = re.compile(r"[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*\.[a-z]{2,}")
#: Names a private network uses, never a company's career site.
_LOCAL = (".localhost", ".local", ".internal", ".lan", ".home.arpa")
def parts(slug: str) -> tuple[str, str]:
"""`(host, domain)` of a slug, lowercased."""
host, _, domain = slug.lower().partition("/")
return host, domain
def _name_ok(name: str) -> bool:
return bool(_NAME.fullmatch(name)) and not name.endswith(_LOCAL)
def slug_ok(slug: str) -> bool:
host, sep, domain = slug.lower().partition("/")
return bool(sep) and _name_ok(host) and _name_ok(domain)
def allowed(slug: str) -> Callable[[str], bool]:
return only(parts(slug)[0])
def careers_url(slug: str) -> str:
return f"https://{parts(slug)[0]}/careers"
def page(get: Get, slug: str, cursor: Any, ask: Ask) -> Page:
"""One page of `/api/pcsx/search` -> `{"status": 200, "data": {"positions":
[...], "count": n}}`, in the one country `ask` names; the next starts at
the offset after this page's positions, and an empty page ends the read.
`query` goes as `query=`."""
host, domain = parts(slug)
start = int(cursor or 0)
country = name_of(ask.countries[0]) if ask.countries else ""
where = f"&location={quote(country)}" if country else ""
words = f"&query={quote(ask.query, safe='')}" if ask.query else ""
answer = json.loads(get(f"https://{host}/api/pcsx/search?domain={domain}"
f"&sort_by=timestamp&start={start}{where}{words}"))
data = answer.get("data") if isinstance(answer, dict) else None
positions = data.get("positions") if isinstance(data, dict) else None
if not isinstance(positions, list):
raise ValueError("not an Eightfold search answer: no data.positions"
+ (f" (status {answer.get('status')})" if isinstance(answer, dict) else ""))
count = data.get("count")
results = [{"id": str(p.get("id") or "")} for p in positions]
return (positions, results, count if isinstance(count, int) else None,
start + len(positions) if positions else None)
def _places(locations: Any) -> list[Place]:
"""The role's places. Eightfold writes each as "city,region,country" with
no space and repeats the name when a city is its own region ("Mexico
City,Mexico City,Mexico"), so the repeats go."""
out: list[Place] = []
for loc in locations if isinstance(locations, list) else []:
names: list[str] = []
for name in str(loc).split(","):
name = name.strip()
if name and name not in names:
names.append(name)
text = ", ".join(names)
add_place(out, place(text))
return out
def rows(positions: list[dict[str, Any]], slug: str) -> list[Row]:
"""A position has `id` (a number, kept as a string), `displayJobId`,
`name`, `locations`, `creationTs` (epoch seconds; `postedTs` is
refreshed in bulk), `department`,
`workLocationOption` and `positionUrl`, the path of the role's page on the
tenant's host. The list has no text, and no pay is stated anywhere."""
host = parts(slug)[0]
out = []
for p in positions:
title = (p.get("name") or "").strip()
source_id = str(p.get("id") or "")
path = str(p.get("positionUrl") or "").strip()
url = f"https://{host}{path}" if path.startswith("/") and path[1:2] != "/" else ""
if not title or not source_id or not is_web_url(url):
continue
places = _places(p.get("locations") or p.get("standardizedLocations"))
out.append({
"source_id": source_id,
"title": title,
"places": places,
"location": "; ".join(pl["text"] for pl in places),
"url": url,
# `postedTs` is refreshed in bulk (a whole page says today);
# `creationTs` is the posting date.
"posted": parse_dt(p.get("creationTs") or p.get("postedTs")),
"department": str(p.get("department") or "").strip(),
"description": "",
"remote": str(p.get("workLocationOption") or "").strip() or None,
"salary_text": "",
})
return out
def detail(get: Get, slug: str, row: Row) -> dict[str, Any]:
"""`/api/pcsx/position_details` of the role -> `data.jobDescription`, the
HTML text of the ad. The same answer repeats the listing's fields, and
`publicUrl`, none of which is needed."""
host, domain = parts(slug)
role = str(row["source_id"])
if not role.isdigit():
raise ValueError(f"not an Eightfold position id: {role!r}")
answer = json.loads(get(f"https://{host}/api/pcsx/position_details"
f"?position_id={role}&domain={domain}&hl=en"))
data = answer.get("data") if isinstance(answer, dict) else None
if not isinstance(data, dict) or "jobDescription" not in data:
raise ValueError("not an Eightfold position: no data.jobDescription")
return {"description": html_text(data["jobDescription"])}