Spaces:
Sleeping
Sleeping
| from duckduckgo_search import DDGS | |
| from typing import List, Dict | |
| import re | |
| class SocialMediaSearchTool: | |
| def __init__(self): | |
| self.ddgs = DDGS() | |
| self.platforms = { | |
| "LinkedIn": r"linkedin\.com/in/", | |
| "GitHub": r"github\.com/", | |
| "Twitter": r"twitter\.com/", | |
| "HuggingFace": r"huggingface\.co/", | |
| "Facebook": r"facebook\.com/", | |
| "Instagram": r"instagram\.com/" | |
| } | |
| def search_profile(self, name: str, platform: str) -> Dict: | |
| query = f"{name} {platform}" | |
| results = self.ddgs.text(query, max_results=5) | |
| for result in results: | |
| if re.search(self.platforms[platform], result["href"]): | |
| return { | |
| "platform": platform, | |
| "url": result["href"], | |
| "title": result["title"], | |
| "description": result["body"] | |
| } | |
| return {"platform": platform, "error": "No profile found"} |