Wire freehire, Jobnet and Akademikernes Jobbank into the CLI, the Sources form, dupes and the docs
Provider names, the CLI's choices and the dupes rule's search hosts now come from readers.PROVIDERS, and the regions, work modes and remote words from the modules' REGIONS, MODES and REMOTE, read with getattr so main works before and after the readers merge. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
018a1ad895
commit
6e6e655203
16 files changed
+422
-39
No files matched your search
+13
-8
@@ -26,9 +26,6 @@ from plugins import readers
|
||||
if TYPE_CHECKING:
|
||||
from app.jobs.discover import Discovery
|
||||
|
||||
#: 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]:
|
||||
"""Switch one board or search on or off. Off closes its open roles and
|
||||
@@ -356,20 +353,28 @@ def seed_companies(store: Store, path: str | Path) -> dict[str, Any]:
|
||||
"problems": problems}
|
||||
|
||||
|
||||
def provider_table(provider: str, name: str) -> dict[str, str]:
|
||||
"""The table `name` (`REGIONS`, `MODES` or `REMOTE`) of a search reader, as
|
||||
the form and the CLI list its values; empty when the provider is not
|
||||
loaded or declares none, so a page works before a reader is merged."""
|
||||
return dict(getattr(readers.PROVIDERS.get(provider), name, None) or {})
|
||||
|
||||
|
||||
def search_params(provider: str, q: str, *, area: int = 0, country: str = "",
|
||||
where: str = "", region: str = "", pages: int = 0) -> dict[str, Any]:
|
||||
where: str = "", region: str = "", remote: str = "",
|
||||
pages: int = 0) -> dict[str, Any]:
|
||||
"""The `params` a search subscription stores, with only the keys its
|
||||
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 provider not in readers.PROVIDERS:
|
||||
raise ValueError(f"provider is one of {', '.join(readers.PROVIDERS)}")
|
||||
if not q.strip():
|
||||
raise ValueError("a search needs a query")
|
||||
module = readers.PROVIDERS[provider]
|
||||
declared = module.READS.filters.declared()
|
||||
given: dict[str, Any] = {"q": q.strip(), "area": area, "country": country,
|
||||
"where": where, "region": region}
|
||||
"where": where, "region": region, "remote": remote}
|
||||
wanted = {name: given[name] for name, dimension in module.PARAMS.items()
|
||||
if dimension in declared}
|
||||
params = module.clean_params(wanted)
|
||||
@@ -379,7 +384,7 @@ def search_params(provider: str, q: str, *, area: int = 0, country: str = "",
|
||||
|
||||
|
||||
def has_key(config: Config, provider: str) -> bool:
|
||||
"""Whether `provider` can run: jobindex and platsbanken always, adzuna with a key in the
|
||||
"""Whether `provider` can run: every provider but adzuna always, adzuna with a key in the
|
||||
config or the environment."""
|
||||
if provider != "adzuna":
|
||||
return True
|
||||
|
||||
Reference in new issue
Block a user