-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
163 lines (126 loc) · 5.07 KB
/
app.py
File metadata and controls
163 lines (126 loc) · 5.07 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from flask import Flask, render_template, request, jsonify
import github_api
from nlp_scoring import analyze_profile
import serper_api
import scholar_api
import orcid
opted_out = set()
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/signin')
def signin():
return render_template('signin.html')
@app.route('/signup')
def signup():
return render_template('signup.html')
@app.route('/finder')
def finder():
return render_template('finder.html')
@app.route('/results', methods=['GET', 'POST'])
def results():
domain = ""
keywords = ""
if request.method == 'POST':
domain = request.form.get('domain', '').strip()
keywords = request.form.get('keywords', '').strip()
keywords_list = [k.strip() for k in keywords.split(",")] if keywords else []
domain_keywords = {domain: keywords_list}
scholar_experts = []
linkedin_experts = []
github_experts = []
orcid_experts = []
"""
# --- ORCID veterans ---
orcid_experts = orcid.get_veteran_profiles(domain, max_profiles = 30)
# --- Scholar veterans ---
for sc in scholar_api.search_scholar_veterans(domain, keywords_list,30):
profile_text = sc.get('profile_text') or (sc.get('title', '') + ' ' + sc.get('interests', ''))
sources = {'scholar': profile_text}
scores_data = analyze_profile(sources, domain_keywords)
confidence_score = max([int(round(score)) for score in scores_data.values()], default=0)
sc['confidence'] = confidence_score
sc['source'] = "Scholar"
scholar_experts.append(sc)
"""
# --- LinkedIn results via Serper API ---
li_results = serper_api.search_linkedin_profiles_concurrent(f"{domain} {' '.join(keywords_list)}")
for item in li_results:
snippet = item["snippet"]
if not serper_api.has_10_years_experience(snippet):
continue
scores = analyze_profile({"linkedin": snippet}, domain_keywords)
confidence_score = int(round(max(scores.values(), default=0)))
linkedin_experts.append({
"name": item["title"].split(" | ")[0],
"contact": item["link"],
"location": None, # Could be extracted with NLP later
"confidence": confidence_score,
"url": item["link"],
"source": "LinkedIn"
})
# --- GitHub Users ---
users = github_api.search_users_by_topic(domain, keywords_list)
for user in users:
username = user.get("login")
if not username:
continue
result = github_api.estimate_experience(username)
if result and result.get('is_veteran'):
sources = {
'github': " ".join([
result.get('bio', '') or '',
result.get('repos_description', '') or '',
result.get('topics', '') or '',
result.get('contributions', '') or ''
])
}
scores_data = analyze_profile(sources, domain_keywords)
confidence_score = max(
[int(round(score)) for score in scores_data.values()],
default=0
)
github_experts.append({
"name": result.get('username'),
"bio": result.get('bio', ''),
"contact": result.get('email', None) or result.get('html_url', ''),
"location": "----",
"confidence": confidence_score,
"url": result.get("html_url"),
"source": "GitHub"
})
else:
print(f"Skipped: {username} (Not enough experience or failed lookup)")
# --- Merge in required order ---
experts_list = scholar_experts + linkedin_experts + github_experts + orcid_experts
# --- Sort all experts descending by confidence score ---
experts_list.sort(key=lambda x: x.get('confidence', 0), reverse=True)
return render_template('results.html',
experts=experts_list,
domain=domain,
keywords=keywords)
@app.post("/opt-out/<profile_id>")
def opt_out(profile_id):
opted_out.add(profile_id)
return jsonify({"status": "ok"})
@app.route('/analyze', methods=['POST'])
def analyze():
if not request.is_json:
return jsonify({'error': 'Request must be JSON'}), 400
data = request.get_json()
if not data:
return jsonify({'error': 'No data provided'}), 400
sources = data.get('sources')
domain_keywords = data.get('domain_keywords')
if not sources or not isinstance(sources, dict):
return jsonify({'error': 'Invalid or missing sources'}), 400
if not domain_keywords or not isinstance(domain_keywords, dict):
return jsonify({'error': 'Invalid or missing domain_keywords'}), 400
try:
result = analyze_profile(sources, domain_keywords)
return jsonify(result)
except Exception as e:
return jsonify({'error': f'Analysis failed: {str(e)}'}), 500
if __name__ == '__main__':
app.run(debug=True)