main.py 545 Bytes
Newer Older
1
from typing import Optional
2
from urllib.parse import urlparse
3
4
5
from pydantic import BaseModel


6
7
8
9
10
11
12
13
14
15
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

16
17
18
19
class SearchResult(BaseModel):
    link: str
    title: Optional[str]
    snippet: Optional[str]