Search providers as reader modules: jobindex, adzuna, platsbanken

Each declares READS with scope=search, keeps every place and hands the excerpt over as teaser. search_params and PROVIDERS follow the declarations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 09:08:25 +02:00
1 parent 4c0da58da7
commit b78c9dfc67
14 files changed
+1202 -17

No files matched your search

+13 -17
View File
@@ -21,12 +21,13 @@ from app.config import Config
from app.models import HAND_REASONS, Company, Subscription, company_key
from app.storage import Store
from app.jobs.pull import FAILING, search_target
from plugins import readers
if TYPE_CHECKING:
from app.jobs.discover import Discovery
#: The providers `plugins.search` runs, and which of them needs a key.
PROVIDERS = ("jobindex", "adzuna", "platsbanken")
#: The providers, from the reader modules that declare `scope="search"`.
PROVIDERS = tuple(readers.PROVIDERS)
def set_fetch(store: Store, sub_id: int, fetch: bool) -> tuple[Subscription, int]:
@@ -339,25 +340,20 @@ def seed_companies(store: Store, path: str | Path) -> dict[str, Any]:
def search_params(provider: str, q: str, *, area: int = 0, country: str = "",
where: str = "", region: str = "", pages: int = 0) -> dict[str, Any]:
"""The `params` a search subscription stores, with only the keys its
provider reads."""
provider reads: those of its module's `PARAMS` whose filter dimension
`READS.filters` declares, cleaned by the module's `clean_params`, which
refuses a value the provider would not accept."""
if provider not in PROVIDERS:
raise ValueError(f"provider is one of {', '.join(PROVIDERS)}")
if not q.strip():
raise ValueError("a search needs a query")
params: dict[str, Any] = {"q": q.strip()}
if provider == "jobindex" and area:
params["area"] = int(area)
if provider == "adzuna":
params["country"] = country.strip().lower()
if where.strip():
params["where"] = where.strip()
if provider == "platsbanken":
from plugins.search import PLATSBANKEN_REGIONS
region = region.strip()
if region and region not in PLATSBANKEN_REGIONS:
raise ValueError("region is empty or the id of a Swedish län")
params["region"] = region
module = readers.PROVIDERS[provider]
declared = module.READS.filters.declared()
given: dict[str, Any] = {"q": q.strip(), "area": area, "country": country,
"where": where, "region": region}
wanted = {name: given[name] for name, dimension in module.PARAMS.items()
if dimension in declared}
params = module.clean_params(wanted)
if pages:
params["pages"] = int(pages)
return params