Spaces:
Sleeping
Sleeping
Update tools/social_media_search.py
Browse files- tools/social_media_search.py +31 -0
tools/social_media_search.py
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import Agent
|
| 2 |
+
from duckduckgo_search import DDGS
|
| 3 |
+
from typing import List, Dict
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class SocialMediaSearchTool:
|
| 8 |
+
def __init__(self):
|
| 9 |
+
self.ddgs = DDGS()
|
| 10 |
+
self.platforms = {
|
| 11 |
+
"LinkedIn": r"linkedin\.com/in/",
|
| 12 |
+
"GitHub": r"github\.com/",
|
| 13 |
+
"Twitter": r"twitter\.com/",
|
| 14 |
+
"HuggingFace": r"huggingface\.co/",
|
| 15 |
+
"Facebook": r"facebook\.com/",
|
| 16 |
+
"Instagram": r"instagram\.com/"
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def search_profile(self, name: str, platform: str) -> Dict:
|
| 20 |
+
query = f"{name} {platform}"
|
| 21 |
+
results = self.ddgs.text(query, max_results=5)
|
| 22 |
+
|
| 23 |
+
for result in results:
|
| 24 |
+
if re.search(self.platforms[platform], result["href"]):
|
| 25 |
+
return {
|
| 26 |
+
"platform": platform,
|
| 27 |
+
"url": result["href"],
|
| 28 |
+
"title": result["title"],
|
| 29 |
+
"description": result["body"]
|
| 30 |
+
}
|
| 31 |
+
return {"platform": platform, "error": "No profile found"}
|