Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Use a more flexible format for curated domains endpoint

Daoud Clarkeb74a94fbda75
diff --git a/mwmbl/crawl.py b/mwmbl/crawl.py
index e7f3f67..1d72fae 100644
--- a/mwmbl/crawl.py
+++ b/mwmbl/crawl.py
@@ -57,7 +57,8 @@ def _fetch_curated_domains() -> set[str]:
headers={"User-Agent": USER_AGENT},
)
response.raise_for_status()
- _curated_domains_cache = set(response.json())
+ data = response.json()
+ _curated_domains_cache = {d["name"] for d in data["domains"]}
_curated_domains_fetched_at = now
except Exception:
logger.exception("Failed to fetch curated domains, using cached value")
diff --git a/mwmbl/crawler/app.py b/mwmbl/crawler/app.py
index c21f38f..3407052 100644
--- a/mwmbl/crawler/app.py
+++ b/mwmbl/crawler/app.py
@@ -239,6 +239,12 @@ def _register_routes(r: Router | NinjaAPI, batch_cache: BatchCache, queued_batch
'status': 'ok'
}
+ class CuratedDomain(Schema):
+ name: str
+
+ class CuratedDomainsResponse(Schema):
+ domains: list[CuratedDomain]
+
@r.get(
'/curated-domains',
summary="Get curated domains for crawling",
@@ -248,9 +254,11 @@ def _register_routes(r: Router | NinjaAPI, batch_cache: BatchCache, queued_batch
"Results are cached server-side for 5 minutes."
),
)
- def get_curated_domains_endpoint(request) -> list[str]:
+ def get_curated_domains_endpoint(request) -> CuratedDomainsResponse:
from mwmbl.search_setup import get_curated_domains
- return sorted(get_curated_domains())
+ return CuratedDomainsResponse(
+ domains=[CuratedDomain(name=d) for d in sorted(get_curated_domains())]
+ )
@r.post(
'/results',