Files
jobboard/plugins/readers/ashby.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

155 lines
6.0 KiB
Python

"""Ashby: `ashby:<job board name>`, the whole board in one JSON answer. A
board name may carry a dot (`jimdo.com`) or be a uuid.
The field map is ported from `openings.go` in
[jobhunt-hq](https://github.com/rembrandtreyes/jobhunt-hq) (MIT).
"""
from __future__ import annotations
import json
import logging
from collections.abc import Callable
from typing import Any
from ._contract import Ask, Fields, Place, Reads, Row
from ._shared import add_place, html_text, is_web_url, num, only, parse_dt, path_slug_ok, pay_line, place, yearly_amount
log = logging.getLogger(__name__)
NAME = "ashby"
LABEL = "Ashby"
RANK = 30
PATTERNS = (
r"jobs\.ashbyhq\.com/([A-Za-z0-9_.-]+)",
r"api\.ashbyhq\.com/posting-api/job-board/([A-Za-z0-9_.-]+)",
)
READS = Reads(
scope="board", listing="whole", text="listing", complete="whole",
places="many", empty="suspect",
fields=Fields(pay="figures", posted="trusted", remote="stated", employment="stated"),
robots=("read: api.ashbyhq.com answers /robots.txt with 401 and no rules, so "
"/posting-api/job-board/<slug> is not disallowed (checked 2026-09-30)"),
)
_API = "api.ashbyhq.com"
def slug_ok(slug: str) -> bool:
return path_slug_ok(slug)
def allowed(slug: str) -> Callable[[str], bool]:
return only(_API)
def careers_url(slug: str) -> str:
return f"https://jobs.ashbyhq.com/{slug}"
def feed_url(slug: str, ask: Ask) -> str:
return f"https://{_API}/posting-api/job-board/{slug}?includeCompensation=true"
def probe_url(slug: str) -> str:
return f"https://{_API}/posting-api/job-board/{slug}"
def probe_ok(body: bytes) -> bool:
"""Ashby answers an empty listing for an unknown name, so a listing
without jobs counts as no board."""
return b'"jobs":[' in body and b'"jobs":[]' not in body
def _salary(components: list[dict[str, Any]]) -> tuple[int | None, int | None, str]:
"""The yearly range from `compensation.summaryComponents` (needs
`?includeCompensation=true` on the feed URL, see `feed_url`): the first
`Salary` component, yearly or monthly (a monthly one multiplied by 12);
an hourly one is left out rather than annualised."""
for component in components:
if component.get("compensationType") != "Salary":
continue
return yearly_amount(component.get("minValue"), component.get("maxValue"),
component.get("currencyCode"), component.get("interval"),
{"1 YEAR": 1, "1 MONTH": 12})
return None, None, ""
def _salary_text(compensation: dict[str, Any]) -> str:
"""One line per `summaryComponents` entry that states a bound, labelled
by the board's own `compensationType` when more than one does (a salary
range beside a bonus range, say); with just the one, the label is left
off, the same as Greenhouse's. `interval` is "<n> <PERIOD>" ("1 YEAR",
"1 HOUR"); the last word, lowered, is the period. With nothing to build
a line from, Ashby's own prose summary (`compensationTierSummary`, else
`scrapeableCompensationSalarySummary`) is what is left to show."""
components = compensation.get("summaryComponents") or []
stated = [c for c in components if num(c.get("minValue")) is not None
or num(c.get("maxValue")) is not None]
lines = []
for component in stated:
period = str(component.get("interval") or "").split(" ")[-1].lower()
line = pay_line(num(component.get("minValue")), num(component.get("maxValue")),
component.get("currencyCode"), period)
if not line:
continue
if len(stated) > 1:
label = str(component.get("compensationType") or "").strip()
line = f"{label}: {line}" if label else line
lines.append(line)
if lines:
return "; ".join(lines)
return str(compensation.get("compensationTierSummary")
or compensation.get("scrapeableCompensationSalarySummary") or "")
def _places(j: dict[str, Any], workplace: str) -> list[Place]:
"""The primary `location`, then each of `secondaryLocations`, in the host's
words. The primary is remote or an office as `workplaceType` says; a
place that names itself remote is remote."""
primary = (j.get("location") or "").strip()
named = [(primary, {"remote": True, "hybrid": False, "onsite": False}.get(workplace.lower()))]
named += [(str((s or {}).get("location") or "").strip(), None)
for s in j.get("secondaryLocations") or []]
out: list[Place] = []
for text, remote in named:
add_place(out, place(text, remote))
return out
def parse(body: bytes, slug: str) -> list[Row]:
data = json.loads(body)
rows = []
for j in data.get("jobs") or []:
title = (j.get("title") or "").strip()
url = (j.get("jobUrl") or j.get("applyUrl") or "").strip()
if not title or not is_web_url(url):
continue
description = j.get("descriptionHtml") or j.get("descriptionPlain") or ""
compensation = j.get("compensation") or {}
salary_min, salary_max, currency = _salary(compensation.get("summaryComponents") or [])
workplace = str(j.get("workplaceType") or "").strip()
places = _places(j, workplace)
row: Row = {
"source_id": str(j.get("id") or ""),
"title": title,
"places": places,
"location": "; ".join(p["text"] for p in places),
"url": url,
"posted": parse_dt(j.get("publishedAt")),
"department": (j.get("department") or j.get("team") or "").strip(),
"description": html_text(description),
"remote": workplace or j.get("isRemote"), # `isRemote` is true for hybrid too
"salary_text": _salary_text(compensation),
"salary_min": salary_min,
"salary_max": salary_max,
"currency": currency,
}
if employment := str(j.get("employmentType") or "").strip():
row["employment"] = employment
rows.append(row)
return rows