"""Teamtailor: `teamtailor:` for acme.teamtailor.com, or, for a career site on the company's own domain, that whole host name: `teamtailor:careers.acme.com`. An RSS feed paged by offset that states no total. Written from live feeds on 2026-09-29; jobhunt-hq did not read Teamtailor. """ from __future__ import annotations import html import re import xml.etree.ElementTree as ET from collections.abc import Callable from typing import Any from desk.sources import strip_html from ._shared import Get, Page, Row, is_web_url, only, parse_dt NAME = "teamtailor" LABEL = "Teamtailor" RANK = 80 PATTERNS = ( r"https?://([a-z0-9-]+)\.teamtailor\.com", # No slug: a career site on the company's own domain, which only loads # Teamtailor's CDN. Discovery reads its board off the page's host. r"cdn\.teamtailor\.com|teamtailor-cdn|teamtailor\.com/assets", ) #: The page size, asked for as `per_page`. A feed with neither parameter #: answers with every role (73 of 73 at Shine, 2026-09-29), but says nowhere #: that it is the whole list, so this reads by page to an empty one; #: `per_page=200` was answered in full too, and the cursor advances by what a #: page returned, so a smaller cap on the host's side would not skip a role. PAGE_SIZE = 50 #: Only a DNS name with a letter in its last label is a site, so an address #: (`127.0.0.1`, `[::1]`) or a single word never names a host the fetch could #: be pointed at; `ats._get` still refuses every host but this one, redirects #: included. _HOST = re.compile(r"[a-z0-9-]+(\.[a-z0-9-]+)*") #: Teamtailor's own namespace in the feed, the `tt:` of `tt:locations`. _TT = "{https://teamtailor.com/locations}" #: Teamtailor's `remoteStatus` -> `store._remote`'s words. `none` says nothing #: about where the role is worked and `temporary` is remote for a spell only, #: so both stay unknown rather than become "onsite" or "remote". _REMOTE = {"fully": "remote", "hybrid": "hybrid", "onsite": "onsite"} def site(slug: str) -> str: """The host a career site is served from: `acme` is acme.teamtailor.com, and a slug with a dot is a site on the company's own domain, `careers.acme.com`, taken whole (the feed path is the same on both).""" slug = slug.strip().lower() return slug if "." in slug else f"{slug}.teamtailor.com" def slug_ok(slug: str) -> bool: host = site(slug) return bool(slug) and slug == slug.strip() and bool(_HOST.fullmatch(host)) \ and not host.rsplit(".", 1)[-1].isdigit() def allowed(slug: str) -> Callable[[str], bool]: return only(site(slug)) def careers_url(slug: str) -> str: return f"https://{site(slug)}/jobs" def probe_url(slug: str) -> str: return f"https://{site(slug)}/jobs.rss" def probe_ok(body: bytes) -> bool: return b"" in body def page(get: Get, slug: str, cursor: Any) -> Page: offset = int(cursor or 0) items = _items(get(f"https://{site(slug)}/jobs.rss?per_page={PAGE_SIZE}&offset={offset}")) results = [{"id": item.findtext("guid") or item.findtext("link") or ""} for item in items] return items, results, None, offset + len(items) if items else None def parse(body: bytes, slug: str) -> list[Row]: return rows(_items(body), slug) def _items(body: bytes) -> list[ET.Element]: """`{site}/jobs.rss` -> `...`, the feed every Teamtailor career site serves (checked live on a dozen sites, 2026-09-29). A missing `channel` is a page that is not a feed, and raises.""" channel = ET.fromstring(body).find("channel") if channel is None: raise ValueError("not a Teamtailor feed: no channel") return channel.findall("item") def rows(items: list[ET.Element], slug: str) -> list[Row]: """One page of items. The item has the title, the job URL (on the site's own domain), a `guid` uuid, `pubDate`, the HTML `description` in full, `remoteStatus` (fully, hybrid, onsite, none or temporary), and, in the `tt:` namespace, `locations` (a list: `city` and `country` each, `name` free text), `department` and `role`, either of which may be empty. `place` joins the distinct locations with "; ", which `country_of` reads a location at a time. No pay is stated anywhere in the feed.""" out = [] for item in items: title = (item.findtext("title") or "").strip() url = (item.findtext("link") or "").strip() if not title or not is_web_url(url): continue places: list[str] = [] for loc in item.findall(f"{_TT}locations/{_TT}location"): city = (loc.findtext(f"{_TT}city") or loc.findtext(f"{_TT}name") or "").strip() country = (loc.findtext(f"{_TT}country") or "").strip() place = city if country == city else ", ".join(p for p in (city, country) if p) if place and place not in places: places.append(place) out.append({ "source_id": (item.findtext("guid") or url).strip(), "title": title, "location": "; ".join(places), "url": url, "posted": parse_dt(item.findtext("pubDate")), "department": ((item.findtext(f"{_TT}department") or "").strip() or (item.findtext(f"{_TT}role") or "").strip()), "description": html.unescape(strip_html(item.findtext("description") or "")), "remote": _REMOTE.get((item.findtext("remoteStatus") or "").strip()), "salary_text": "", # Teamtailor's feed states no pay at all }) return out