Update app.py
Browse files
app.py
CHANGED
|
@@ -66,44 +66,43 @@ def calculate_similarity(name1, name2):
|
|
| 66 |
|
| 67 |
|
| 68 |
def fetch_linkedin_links(query, api_key, applicant_name):
|
| 69 |
-
"""Fetches LinkedIn profile links using
|
| 70 |
-
linkedin_regex = r'https://(www|[a-z]{2})\.linkedin\.com/.*'
|
| 71 |
-
|
| 72 |
try:
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
"Authorization": f"Bearer {api_key}"
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
encoded_query = quote_plus(query)
|
| 79 |
-
search_url = f"https://www.google.com/search?q={encoded_query}"
|
| 80 |
|
| 81 |
payload = {
|
| 82 |
-
"
|
| 83 |
-
"
|
| 84 |
-
"format": "raw"
|
|
|
|
|
|
|
|
|
|
| 85 |
}
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
response.raise_for_status()
|
| 89 |
|
| 90 |
html = response.text
|
| 91 |
-
|
| 92 |
-
linkedin_links = list(set(["https://" + link for link in linkedin_links])) # De-duplicate
|
| 93 |
|
| 94 |
-
|
|
|
|
| 95 |
profile_name = get_name_from_url(link)
|
| 96 |
if profile_name:
|
| 97 |
similarity = calculate_similarity(applicant_name, profile_name)
|
| 98 |
if similarity >= 0.5:
|
| 99 |
return link
|
| 100 |
-
|
| 101 |
return None
|
| 102 |
-
|
| 103 |
except Exception as e:
|
| 104 |
st.error(f"Error fetching link for query '{query}': {e}")
|
| 105 |
return None
|
| 106 |
-
|
| 107 |
|
| 108 |
def process_file(file, api_key):
|
| 109 |
"""Processes the uploaded Excel file to fetch LinkedIn profile links."""
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
def fetch_linkedin_links(query, api_key, applicant_name):
|
| 69 |
+
"""Fetches LinkedIn profile links using the correct BrightData API."""
|
|
|
|
|
|
|
| 70 |
try:
|
| 71 |
+
url = "https://api.brightdata.com/request"
|
| 72 |
+
google_search_url = f"https://www.google.com/search?q={query}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
payload = {
|
| 75 |
+
"url": google_search_url,
|
| 76 |
+
"zone": "residential", # Replace with your actual zone if needed
|
| 77 |
+
"format": "raw",
|
| 78 |
+
"method": "GET",
|
| 79 |
+
"country": "us", # Optional: set your preferred location
|
| 80 |
+
"data_format": "html"
|
| 81 |
}
|
| 82 |
|
| 83 |
+
headers = {
|
| 84 |
+
"Authorization": f"Bearer {api_key}",
|
| 85 |
+
"Content-Type": "application/json"
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
response = requests.post(url, json=payload, headers=headers)
|
| 89 |
response.raise_for_status()
|
| 90 |
|
| 91 |
html = response.text
|
| 92 |
+
linkedin_regex = r'https://(?:[a-z]{2,3}\.)?linkedin\.com/in/[a-zA-Z0-9\-_/]+'
|
|
|
|
| 93 |
|
| 94 |
+
links = re.findall(linkedin_regex, html)
|
| 95 |
+
for link in links:
|
| 96 |
profile_name = get_name_from_url(link)
|
| 97 |
if profile_name:
|
| 98 |
similarity = calculate_similarity(applicant_name, profile_name)
|
| 99 |
if similarity >= 0.5:
|
| 100 |
return link
|
|
|
|
| 101 |
return None
|
|
|
|
| 102 |
except Exception as e:
|
| 103 |
st.error(f"Error fetching link for query '{query}': {e}")
|
| 104 |
return None
|
| 105 |
+
|
| 106 |
|
| 107 |
def process_file(file, api_key):
|
| 108 |
"""Processes the uploaded Excel file to fetch LinkedIn profile links."""
|