forked from Tejeswar001/RoleRadar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserper_api.py
More file actions
45 lines (38 loc) · 1.29 KB
/
serper_api.py
File metadata and controls
45 lines (38 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from config import SERPER_API_KEY
import requests
import re
from datetime import datetime
SERPER_HEADERS = {
"X-API-KEY": SERPER_API_KEY,
"Content-Type": "application/json"
}
def search_linkedin_profiles(query):
url = "https://google.serper.dev/search"
payload = {
"q": f"site:linkedin.com/in/ {query}"
}
response = requests.post(url, headers=SERPER_HEADERS, json=payload)
return response.json()
def has_10_years_experience(snippet):
if not snippet:
return False
# Match phrases like "10+ years", "over 12 years", "15 yrs"
match = re.search(r"(1[0-9]|[2-9][0-9])\+?\s*(years?|yrs?)", snippet.lower())
if match:
return True
# Match any year (e.g., "since 2012") and calculate difference
year_matches = re.findall(r"(19|20)\d{2}", snippet)
for year_str in year_matches:
year = int(year_str)
if datetime.now().year - year >= 10:
return True
return False
if __name__ == "__main__":
results = search_linkedin_profiles("AI")
for item in results.get("organic", []):
if has_10_years_experience(item.get("snippet", "")):
print("🔍 Veteran Found:")
print(item["title"])
print(item["link"])
print(item.get("snippet"))
print("-----")