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-17 07:36:26 +00:00
|
|
|
def get_filtered_results(results, filter_list):
|
|
|
|
if not filter_list:
|
2024-06-13 00:14:48 +00:00
|
|
|
return results
|
|
|
|
filtered_results = []
|
|
|
|
for result in results:
|
|
|
|
domain = urlparse(result["url"]).netloc
|
2024-06-17 07:36:26 +00:00
|
|
|
if any(domain.endswith(filtered_domain) for filtered_domain in filter_list):
|
2024-06-13 00:14:48 +00:00
|
|
|
filtered_results.append(result)
|
|
|
|
return filtered_results
|
|
|
|
|
2024-06-17 21:32:23 +00:00
|
|
|
|
2024-05-06 04:27:46 +00:00
|
|
|
class SearchResult(BaseModel):
|
|
|
|
link: str
|
|
|
|
title: Optional[str]
|
|
|
|
snippet: Optional[str]
|