Share the readers' place, table-lookup and country helpers, unify the employment vocabulary, and list the enrich switch with the stages
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ca80219bbb
commit
903b69b6d3
34 files changed
+290
-207
No files matched your search
@@ -25,8 +25,8 @@ from typing import Any
|
||||
|
||||
from desk.sources import strip_html
|
||||
|
||||
from ._contract import Ask, Fields, Place, Reads, Row
|
||||
from ._shared import Get, parse_dt
|
||||
from ._contract import Ask, Fields, Reads, Row
|
||||
from ._shared import Get, parse_dt, place, table_word
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -70,7 +70,7 @@ _SENIORITY = {"student": "intern", "internship": "intern", "trainee": "intern",
|
||||
#: The embed's `employment_type` -> the app's employment words.
|
||||
_EMPLOYMENT = {"full-time": "full_time", "full time": "full_time", "part-time": "part_time",
|
||||
"part time": "part_time", "contract": "contract", "consultant": "contract",
|
||||
"temporary": "temporary", "internship": "intern", "intern": "intern",
|
||||
"temporary": "temporary", "internship": "internship", "intern": "internship",
|
||||
"freelance": "freelance", "summer job": "temporary", "seasonal": "temporary"}
|
||||
|
||||
_ASSIGNMENT = "JBL.embed_v2['jobs'] = "
|
||||
@@ -179,22 +179,6 @@ def _published(value: Any) -> Any:
|
||||
return parse_dt(f"{match.group(3)}-{month:02d}-{int(match.group(2)):02d}")
|
||||
|
||||
|
||||
def _mapped(table: dict[str, str], value: Any, what: str) -> str | None:
|
||||
"""`table`'s word for the host's `value`; None when the host states none
|
||||
or the table does not know it (logged, so the table can grow)."""
|
||||
word = str(value or "").strip()
|
||||
if not word:
|
||||
return None
|
||||
found = table.get(word.lower())
|
||||
if found is None:
|
||||
log.debug("jobylon: unknown %s %r", what, word)
|
||||
return found or None
|
||||
|
||||
|
||||
def _place(text: str) -> Place:
|
||||
return {"text": text, "remote": True if re.search(r"\bremote\b", text, re.I) else None}
|
||||
|
||||
|
||||
def parse(body: bytes, slug: str) -> list[Row]:
|
||||
"""The embed page -> one row per role. `posted` is the day `published_date`
|
||||
names, which `detail` replaces with the exact time. `location` joins the
|
||||
@@ -210,7 +194,7 @@ def parse(body: bytes, slug: str) -> list[Row]:
|
||||
if not title or not job_id or not _ROLE_PATH.fullmatch(path):
|
||||
continue
|
||||
function = str(j.get("function") or "").strip()
|
||||
places = [_place(name) for name in dict.fromkeys(
|
||||
places = [place(name) for name in dict.fromkeys(
|
||||
str(name).strip() for name in j.get("locations") or [] if str(name).strip())]
|
||||
row: Row = {
|
||||
"source_id": job_id,
|
||||
@@ -229,9 +213,9 @@ def parse(body: bytes, slug: str) -> list[Row]:
|
||||
summary = " ".join(html.unescape(strip_html(str(j.get("summary") or ""))).split())
|
||||
if summary and summary != "None":
|
||||
row["teaser"] = summary
|
||||
if seniority := _mapped(_SENIORITY, j.get("experience"), "experience"):
|
||||
if seniority := table_word(_SENIORITY, j.get("experience"), log, "experience"):
|
||||
row["seniority"] = seniority
|
||||
if employment := _mapped(_EMPLOYMENT, j.get("employment_type"), "employment_type"):
|
||||
if employment := table_word(_EMPLOYMENT, j.get("employment_type"), log, "employment_type"):
|
||||
row["employment"] = employment
|
||||
out.append(row)
|
||||
return out
|
||||
@@ -252,8 +236,8 @@ def detail(get: Get, slug: str, row: Row) -> dict[str, Any]:
|
||||
else:
|
||||
raise ValueError("no JobPosting on the role's page")
|
||||
places = []
|
||||
for place in data.get("jobLocation") or []:
|
||||
address = (place or {}).get("address") or {}
|
||||
for loc in data.get("jobLocation") or []:
|
||||
address = (loc or {}).get("address") or {}
|
||||
name = str(address.get("streetAddress") or address.get("addressLocality") or "").strip()
|
||||
if name and name not in places:
|
||||
places.append(name)
|
||||
@@ -263,5 +247,5 @@ def detail(get: Get, slug: str, row: Row) -> dict[str, Any]:
|
||||
}
|
||||
if places:
|
||||
found["location"] = "; ".join(places)
|
||||
found["places"] = [_place(name) for name in places]
|
||||
found["places"] = [place(name) for name in places]
|
||||
return found
|
||||
Reference in new issue
Block a user