"""Personio: `personio:`, the whole board in one XML answer from the company's own subdomain of jobs.personio.de. Written from one real board on 2026-09-23; jobhunt-hq did not read Personio. """ from __future__ import annotations import xml.etree.ElementTree as ET from collections.abc import Callable from desk.sources import strip_html from ._shared import Row, label_slug_ok, num, only, parse_dt, pay_line, yearly_amount NAME = "personio" LABEL = "Personio" RANK = 70 PATTERNS = (r"https?://([a-z0-9-]+)\.jobs\.personio\.(?:de|com)",) #: Personio's `salaryInformation/type` spellings, to the plain period word #: `pay_line` wants ("yearly" -> "year"). Anything else is passed through. _PERIODS = {"yearly": "year", "monthly": "month", "hourly": "hour", "daily": "day", "weekly": "week"} def slug_ok(slug: str) -> bool: return label_slug_ok(slug) def allowed(slug: str) -> Callable[[str], bool]: """The company's own subdomain, so one company's slug cannot pass for another's.""" return only(f"{slug}.jobs.personio.de") def careers_url(slug: str) -> str: return f"https://{slug}.jobs.personio.de" def feed_url(slug: str) -> str: return f"https://{slug}.jobs.personio.de/xml" def probe_url(slug: str) -> str: return feed_url(slug) def probe_ok(body: bytes) -> bool: return b"" in body def _salary_text(salary_info: ET.Element) -> str: """One line from a `` element, whatever its `type`, including an hourly or daily one that `yearly_amount` drops from the columns.""" period_raw = (salary_info.findtext("type") or "").strip().lower() period = _PERIODS.get(period_raw, period_raw) return pay_line(num(salary_info.findtext("min")), num(salary_info.findtext("max")), salary_info.findtext("currencyCode"), period) def parse(body: bytes, slug: str) -> list[Row]: """`{slug}.jobs.personio.de/xml` -> `...`. No job URL in the feed itself; Personio's own page is `/job/{id}`, confirmed live against a real posting (2026-09-23).""" root = ET.fromstring(body) rows = [] for position in root.findall("position"): job_id = (position.findtext("id") or "").strip() title = (position.findtext("name") or "").strip() if not job_id or not title: continue description = " ".join( (value.text or "") for value in position.findall("jobDescriptions/jobDescription/value")) salary_info = position.find("salaryInformation") salary_min = salary_max = None currency = "" salary_text = "" if salary_info is not None: salary_min, salary_max, currency = yearly_amount( salary_info.findtext("min"), salary_info.findtext("max"), salary_info.findtext("currencyCode"), salary_info.findtext("type"), {"yearly": 1, "monthly": 12}) salary_text = _salary_text(salary_info) rows.append({ "source_id": job_id, "title": title, "location": (position.findtext("office") or "").strip(), "url": f"https://{slug}.jobs.personio.de/job/{job_id}", "posted": parse_dt(position.findtext("createdAt")), "department": (position.findtext("department") or "").strip(), "description": strip_html(description), "remote": "remote" in (position.findtext("office") or "").lower() or None, "salary_text": salary_text, "salary_min": salary_min, "salary_max": salary_max, "currency": currency, }) return rows