You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
672 B
26 lines
672 B
import validators
|
|
|
|
from typing import Optional
|
|
from urllib.parse import urlparse
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
def get_filtered_results(results, filter_list):
|
|
if not filter_list:
|
|
return results
|
|
filtered_results = []
|
|
for result in results:
|
|
url = result.get("url") or result.get("link", "")
|
|
if not validators.url(url):
|
|
continue
|
|
domain = urlparse(url).netloc
|
|
if any(domain.endswith(filtered_domain) for filtered_domain in filter_list):
|
|
filtered_results.append(result)
|
|
return filtered_results
|
|
|
|
|
|
class SearchResult(BaseModel):
|
|
link: str
|
|
title: Optional[str]
|
|
snippet: Optional[str]
|
|
|