"""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 logging import xml.etree.ElementTree as ET from collections.abc import Callable from desk.sources import strip_html from ._contract import Ask, Fields, Place, Reads from ._shared import Row, add_place, label_slug_ok, num, only, parse_dt, pay_line, place, table_word, yearly_amount log = logging.getLogger(__name__) NAME = "personio" LABEL = "Personio" RANK = 70 PATTERNS = (r"https?://([a-z0-9-]+)\.jobs\.personio\.(?:de|com)",) READS = Reads( scope="board", listing="whole", text="listing", complete="whole", places="many", fields=Fields(pay="figures", posted="trusted", seniority="stated", employment="stated"), robots="api: no robots.txt check needed (public board API), 2026-09-30", ) #: `seniority` -> the app's levels. `experienced` is what most roles say and #: names no level, so it is known and maps to none; a word not listed is #: logged at debug level so the table can grow. _SENIORITY = {"entry-level": "junior", "student": "intern", "executive": "exec", "experienced": ""} #: `employmentType` when it is not the usual permanent contract, to the app's #: employment words; `permanent` says nothing about the hours, so `schedule` #: decides then. _CONTRACT = {"temporary": "temporary", "freelance": "contract", "intern": "internship", "working_student": "internship", "trainee": "internship"} _SCHEDULE = {"full-time": "full_time", "part-time": "part_time"} #: 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, ask: Ask = Ask()) -> 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 _seniority(word: str) -> str | None: return table_word(_SENIORITY, word, log, "seniority") def _employment(position: ET.Element) -> str | None: contract = (position.findtext("employmentType") or "").strip().lower() schedule = (position.findtext("schedule") or "").strip().lower() if contract in _CONTRACT: return _CONTRACT[contract] if contract and contract != "permanent": log.debug("personio: unknown employmentType %r", contract) return _SCHEDULE.get(schedule) def _places(position: ET.Element) -> list[Place]: """The `office` and every `additionalOffices/office`, each once. The feed has no remote flag; an office named "Remote" or "Berlin (Remote)" is remote, any other says nothing.""" found: list[Place] = [] names = [position.findtext("office"), *(o.text for o in position.findall("additionalOffices/office"))] for name in names: text = (name or "").strip() add_place(found, place(text)) return found 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). `additionalOffices` lists the other places of a role (116 of 320 at the three boards read); `seniority` is one of entry-level, experienced, executive, student, and `schedule` and `employmentType` state the hours and the contract.""" 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) places = _places(position) rows.append({ "source_id": job_id, "title": title, "places": places, "location": "; ".join(p["text"] for p in places), "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": any(p["remote"] for p in places) or None, "seniority": _seniority(position.findtext("seniority") or ""), "employment": _employment(position), "salary_text": salary_text, "salary_min": salary_min, "salary_max": salary_max, "currency": currency, }) return rows