2024-05-06 04:27:46 +00:00
|
|
|
from typing import Optional
|
2024-06-13 00:14:48 +00:00
|
|
|
from urllib.parse import urlparse
|
2024-05-06 04:27:46 +00:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
2024-06-13 00:14:48 +00:00
|
|
|
def filter_by_whitelist(results, whitelist):
|
|
|
|
if not whitelist:
|
|
|
|
return results
|
|
|
|
filtered_results = []
|
|
|
|
for result in results:
|
|
|
|
domain = urlparse(result["url"]).netloc
|
|
|
|
if any(domain.endswith(whitelisted_domain) for whitelisted_domain in whitelist):
|
|
|
|
filtered_results.append(result)
|
|
|
|
return filtered_results
|
|
|
|
|
2024-05-06 04:27:46 +00:00
|
|
|
class SearchResult(BaseModel):
|
|
|
|
link: str
|
|
|
|
title: Optional[str]
|
|
|
|
snippet: Optional[str]
|