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
@@ -8,6 +8,7 @@ import it without either importing the other. The leading underscore keeps
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import re
|
||||
from collections.abc import Callable
|
||||
from datetime import UTC, datetime
|
||||
@@ -16,6 +17,8 @@ from typing import Any, Protocol
|
||||
|
||||
import httpx
|
||||
|
||||
from ._contract import Place
|
||||
|
||||
#: What an undeclared module's parser turns a feed into; a module that
|
||||
#: declares `READS` returns `_contract.Row`, which adds `places` and `teaser`.
|
||||
#: One dict per row, with the keys
|
||||
@@ -192,3 +195,59 @@ def pay_line(lo: float | None, hi: float | None, currency: Any, period: str) ->
|
||||
tail = f" per {period}" if period else ""
|
||||
code = str(currency or "").strip().upper()
|
||||
return f"{code} {bounds}{tail}" if code else f"{bounds}{tail} (no currency stated)"
|
||||
|
||||
|
||||
#: The employment words a row's `employment` may hold, for every host. A
|
||||
#: host's table maps its own words onto these; a word that names none of them
|
||||
#: (a permanent contract says nothing about hours) maps to "".
|
||||
EMPLOYMENTS = ("full_time", "part_time", "contract", "temporary", "internship", "freelance")
|
||||
|
||||
_REMOTE_WORD = re.compile(r"\bremote\b", re.IGNORECASE)
|
||||
|
||||
|
||||
def place(text: str, remote: bool | None = None) -> Place:
|
||||
"""A `Place` for `text`: remote when the text says the word `remote`,
|
||||
otherwise as `remote` says (None when the host says nothing)."""
|
||||
return {"text": text, "remote": True if _REMOTE_WORD.search(text) else remote}
|
||||
|
||||
|
||||
def add_place(found: list[Place], entry: Place) -> None:
|
||||
"""Append `entry` to `found` unless its text is empty or already there;
|
||||
the host's order is kept."""
|
||||
if entry["text"] and entry["text"] not in (p["text"] for p in found):
|
||||
found.append(entry)
|
||||
|
||||
|
||||
def table_word(table: dict[str, str], value: Any, log: logging.Logger, what: str) -> str | None:
|
||||
"""`table`'s word for a host's `value`, looked up without case. None when
|
||||
the host states none, when the table maps the word to "" (a known word
|
||||
that names no level, such as `experienced`), or when the table does not
|
||||
know it; that last case is logged at debug level 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("%s: unknown %s %r", log.name.rsplit(".", 1)[-1], what, word)
|
||||
return found or None
|
||||
|
||||
|
||||
def country_if_single(codes: Any) -> str | None:
|
||||
"""The one code among `codes` when there is exactly one, else None: a
|
||||
country is stated for a role only when all its places share it."""
|
||||
return next(iter(codes)) if len(codes) == 1 else None
|
||||
|
||||
|
||||
#: "Birkerød, Hybrid position", "Nordhavn og mulighed for hjemmearbejde".
|
||||
_HYBRID = re.compile(r"\bhybrid|hjemmearbejde", re.IGNORECASE)
|
||||
_REMOTE = re.compile(
|
||||
r"\bremote\b|fjernarbejde|fuldt hjemmearbejde|distansarbete|på distans", re.IGNORECASE)
|
||||
|
||||
|
||||
def remote_word(text: str) -> str | None:
|
||||
"""`remote`, `hybrid` or None: the word a search provider's headline or
|
||||
town line says about where the work is done, in Danish, Swedish and
|
||||
English. A board states its own remote flag and needs none of this."""
|
||||
if _REMOTE.search(text):
|
||||
return "remote"
|
||||
return "hybrid" if _HYBRID.search(text) else None
|
||||
Reference in new issue
Block a user