-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
947 lines (795 loc) · 37.9 KB
/
app.py
File metadata and controls
947 lines (795 loc) · 37.9 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
from flask import Flask, render_template, request, redirect, url_for, flash, session, jsonify
import os
import cloudinary
import cloudinary.uploader
import requests
from collections import Counter
#from flask import current_app
import re
from googleapiclient.discovery import build
from werkzeug.utils import secure_filename
from werkzeug.security import generate_password_hash, check_password_hash
from werkzeug.security import generate_password_hash, check_password_hash
from datetime import datetime
from models import db, Student, Recruiter, Admin, Post, Comment, Internship, Like, Notification,SkillResource,Report,Application
from sklearn.feature_extraction.text import TfidfVectorizer
from flask_mail import Mail, Message
app = Flask(__name__)
#mail = Mail(app)
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = os.getenv('MAIL_USERNAME', 'your-email@gmail.com')
app.config['MAIL_PASSWORD'] = os.getenv('MAIL_PASSWORD', 'your-app-password')
app.config['MAIL_DEFAULT_SENDER'] = app.config['MAIL_USERNAME']
mail = Mail(app)
# 1. SETUP & CONFIGURATION
basedir = os.path.abspath(os.path.dirname(__file__))
# --- 1. CONFIGURATION & SECRETS ---
# Using environment variables for security. Local defaults are provided as fallbacks.
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', 'postgresql://postgres.rmknqhaztehgtwigsprs:prabinrokaya123%40%23@aws-1-ap-south-1.pooler.supabase.com:6543/postgres')
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'skillsync_2026_super_secret')
# Encoded version if the standard one fails
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', 'postgresql://postgres.rmknqhaztehgtwigsprs:prabinrokaya123%40%23@aws-1-ap-south-1.pooler.supabase.com:6543/postgres')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
UPLOAD_FOLDER = os.path.join('static', 'uploads')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# Cloudinary Setup for persistent image hosting on Render
cloudinary.config(
cloud_name = os.getenv('CLOUDINARY_NAME'),
api_key = os.getenv('CLOUDINARY_KEY'),
api_secret = os.getenv('CLOUDINARY_SECRET'),
secure = True)
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
db.init_app(app)
#with app.app_context():
#db.create_all()
# --- 2. CORE PAGE ROUTES ---
@app.route('/')
def home():
return render_template('index.html')
@app.route('/about-us')
def about_us(): return render_template('about_us.html')
@app.route('/feedback')
def feedback(): return render_template('feedback.html')
@app.route('/privacy-policy')
def privacy_policy(): return render_template('privacy_policy.html')
@app.route('/user-agreement')
def user_agreement(): return render_template('user_agreement.html')
@app.route('/copyright')
def copyright(): return render_template('copyright.html')
@app.route('/cookie-policy')
def cookie_policy(): return render_template('cookie_policy.html')
@app.route('/forgot-password')
def forget(): return render_template('forget.html')
@app.route('/community')
def community(): return render_template('community.html')
# --- 3. AUTHENTICATION ROUTES ---
@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
first_name = request.form.get('firstName')
last_name = request.form.get('lastName')
full_name = f"{first_name} {last_name}"
email = request.form.get('email')
password = request.form.get('password')
role = request.form.get('role')
company = request.form.get('companyName')
if Student.query.filter_by(email=email).first() or Recruiter.query.filter_by(email=email).first():
flash('Email already registered!', 'danger')
return redirect(url_for('register'))
hashed_pw = generate_password_hash(password, method='pbkdf2:sha256')
if role == 'student':
new_user = Student(name=full_name, email=email, password=hashed_pw)
else:
new_user = Recruiter(name=full_name, email=email, password=hashed_pw,
company_name=company if company else "Independent")
db.session.add(new_user)
db.session.commit()
flash('Registration successful! Please log in.', 'success')
return redirect(url_for('login'))
return render_template('register.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
email = request.form.get('email')
password = request.form.get('password')
# 1. ADMIN CHECK
admin = Admin.query.filter_by(email=email).first()
if admin:
# This checks BOTH the hashed password and the plain text 'admin123'
if check_password_hash(admin.password, password) or admin.password == password:
session['user_id'] = admin.admin_id
session['role'] = 'admin'
session['name'] = admin.name
return redirect(url_for('admin_dashboard'))
# 2. STUDENT CHECK
student = Student.query.filter_by(email=email).first()
# FIX: Check if student exists before checking password
if student and (check_password_hash(student.password, password) or student.password == password):
# FIX: Changed 'students' to 'student' (the variable defined above)
# FIX: Use 'student_id' as defined in your model
session['user_id'] = student.student_id
session['role'] = 'student'
session['name'] = student.name
return redirect(url_for('student_feed'))
# 3. RECRUITER CHECK
recruiter = Recruiter.query.filter_by(email=email).first()
# FIX: Check if recruiter exists before checking password
if recruiter and (check_password_hash(recruiter.password, password) or recruiter.password == password):
# FIX: Use 'recruiter_id' (assuming your table uses this naming convention)
session['user_id'] = recruiter.recruiter_id
session['role'] = 'recruiter'
session['name'] = recruiter.name
return redirect(url_for('recruiter_dashboard'))
flash("Invalid Credentials", "danger")
return render_template('login.html')
@app.route('/logout')
def logout():
session.clear()
return redirect(url_for('home'))
# --- 4. DASHBOARD ROUTES ---
top_skills_cache = {"data": [], "timestamp": None}
@app.route('/student-feed')
def student_feed():
if 'user_id' not in session or session.get('role') != 'student':
return redirect(url_for('login'))
user = db.session.get(Student, session['user_id'])
posts = Post.query.order_by(Post.date_posted.desc()).all()
from models import Application # Ensure Application is imported
user_applications = Application.query.filter_by(student_id=user.student_id).all()
applied_post_ids = [app.post_id for app in user_applications]
notifications = Notification.query.filter_by(
recipient_id=session['user_id'],
recipient_role='student' # Filter specifically for students
).order_by(Notification.date_created.desc()).limit(10).all()
unread_count = Notification.query.filter_by(
recipient_id=session['user_id'],
recipient_role='student',
is_read=False
).count()
all_internships = Post.query.filter_by(can_apply=True).all()
market_text = " ".join([p.content for p in all_internships])
skills_found = extract_skills_pro(market_text)
top_skills = Counter(skills_found).most_common(5)
return render_template('student.html',
user=user,
user_name=user.name,
user_role='student',
posts=posts,
notifications=notifications,
unread_count=unread_count,
Student=Student,
Recruiter=Recruiter,
applied_post_ids=applied_post_ids # <--- MAKE SURE THIS IS HERE
)
@app.route('/recruiter/dashboard')
def recruiter_dashboard():
if 'user_id' not in session or session.get('role') != 'recruiter':
return redirect(url_for('login'))
user = db.session.get(Recruiter, session['user_id'])
# This fetches ALL posts from the database, newest first
posts = Post.query.order_by(Post.date_posted.desc()).all()
notifications = Notification.query.filter_by(
recipient_id=session['user_id'],
recipient_role='recruiter' # Filter specifically for recruiters
).order_by(Notification.date_created.desc()).limit(10).all()
unread_count = Notification.query.filter_by(
recipient_id=session['user_id'],
recipient_role='recruiter',
is_read=False
).count()
return render_template('recruiter.html',
user=user,
user_name=user.name,
user_role='recruiter',
posts=posts,
notifications=notifications,
unread_count=unread_count,
Student=Student, # Required for the post header logic
Recruiter=Recruiter # Required for the post header logic
)
@app.route('/admin/dashboard')
def admin_dashboard():
if 'user_id' not in session or session.get('role') != 'admin':
return redirect(url_for('login'))
stats = {
'students': Student.query.count(),
'recruiters': Recruiter.query.count(),
'posts': Post.query.count(),
'reports': Report.query.count()
}
# Getting data for management tables
reports = Report.query.order_by(Report.date_sent.desc()).all()
unverified_recruiters = Recruiter.query.filter_by(is_verified=False).all()
all_posts = Post.query.order_by(Post.date_posted.desc()).limit(20).all()
return render_template('admin.html',
stats=stats,
reports=reports,
unverified_recruiters=unverified_recruiters, # Match the HTML loop name
recent_posts=all_posts) # Match the HTML loop name
@app.route('/admin/change-password', methods=['POST'])
def admin_change_password():
if session.get('role') != 'admin':
return redirect(url_for('login'))
new_password = request.form.get('new_password')
admin_user = Admin.query.filter_by(email="admin@skillsync.com").first()
if admin_user and new_password:
admin_user.password = generate_password_hash(new_password)
db.session.commit()
flash("Admin password updated!", "success")
return redirect(url_for('admin_dashboard', _anchor='settings'))
@app.route('/admin/verify-recruiter/<int:rec_id>')
def verify_recruiter(rec_id):
if session.get('role') != 'admin':
return redirect(url_for('login'))
recruiter = Recruiter.query.get_or_404(rec_id)
recruiter.is_verified = True
db.session.commit()
return redirect(url_for('admin_dashboard'))
@app.route('/admin/delete-post/<int:post_id>')
def admin_delete_post(post_id):
if session.get('role') != 'admin':
return redirect(url_for('login'))
post = Post.query.get_or_404(post_id)
db.session.delete(post)
db.session.commit()
return redirect(url_for('admin_dashboard'))
@app.route('/admin/dismiss-report/<int:report_id>')
def dismiss_report(report_id):
if session.get('role') != 'admin': return redirect(url_for('login'))
report = Report.query.get(report_id)
if report:
db.session.delete(report)
db.session.commit()
return redirect(url_for('admin_dashboard'))
# --- 5. INTERACTION ROUTES ---
@app.route('/create-post', methods=['POST'])
def create_post():
if 'user_id' not in session: return redirect(url_for('login'))
new_post = Post(
content=request.form.get('content'),
author_name=session['name'],
author_role=session['role'],
author_id=session['user_id'],
can_apply='can_apply' in request.form
)
db.session.add(new_post)
db.session.commit()
return redirect(request.referrer or url_for('home'))
# ================= DELETE POST =================
@app.route('/delete_post/<int:post_id>')
def delete_post(post_id):
if 'user_id' not in session: return redirect(url_for('login'))
post = db.session.get(Post, post_id)
if not post:
flash("Post not found.", "warning")
return redirect(request.referrer)
# Check permission (ID + ROLE)
if post.author_id != session.get('user_id') or post.author_role != session.get('role'):
flash("You do not have permission to delete this post!", "danger")
return redirect(request.referrer)
db.session.delete(post)
db.session.commit() # This also deletes associated Likes and Comments because of cascade
flash("Post deleted successfully.", "success")
return redirect(request.referrer)
# ================= LIKE POST (With Multi-User Tracking) =================
@app.route('/like/<int:post_id>')
def like_post(post_id):
if 'user_id' not in session: return redirect(url_for('login'))
u_id = session.get('user_id')
u_role = session.get('role')
post = db.session.get(Post, post_id)
if post:
existing_like = Like.query.filter_by(user_id=u_id, user_role=u_role, post_id=post_id).first()
if not existing_like:
# 1. Add the like
new_like = Like(user_id=u_id, user_role=u_role, post_id=post_id)
db.session.add(new_like)
post.likes_count = (post.likes_count or 0) + 1
# 2. THE FIX: Define the message and check for duplicates
notif_msg = f"liked your post: {post.content[:20]}..."
# Check if this specific notification already exists
already_notified = Notification.query.filter_by(
recipient_id=post.author_id,
recipient_role=post.author_role, # Matches the author's role
sender_name=session.get('name'),
message=notif_msg
).first()
# 3. Only add if it's not a duplicate and not liking own post
if not already_notified and (post.author_id != u_id or post.author_role != u_role):
new_notif = Notification(
recipient_id=post.author_id,
recipient_role=post.author_role, # This ensures it goes to the right person
sender_name=session.get('name'),
message=notif_msg
)
db.session.add(new_notif)
db.session.commit()
else:
# Unlike logic
db.session.delete(existing_like)
post.likes_count = max(0, post.likes_count - 1)
db.session.commit()
return redirect(request.referrer or url_for('student_feed'))
# ================= ADD COMMENT =================
@app.route('/comment/<int:post_id>', methods=['POST'])
def add_comment(post_id):
if 'user_id' not in session: return redirect(url_for('login'))
post = db.session.get(Post, post_id)
text = request.form.get('comment_text')
if text and post:
# Create the comment
comment = Comment(
text=text,
author_name=session['name'],
author_id=session['user_id'],
author_role=session['role'],
post_id=post_id
)
db.session.add(comment)
# Create notification for author
if post.author_id != session['user_id'] or post.author_role != session['role']:
new_notif = Notification(
recipient_id=post.author_id,
recipient_role=post.author_role,
sender_name=session['name'],
message=f"commented on your post"
)
db.session.add(new_notif)
db.session.commit()
return redirect(request.referrer)
# --- 6. PROFILE EDITING ---
@app.route('/edit-profile', methods=['POST'])
def edit_profile():
if 'user_id' not in session or session['role'] != 'student':
return redirect(url_for('login'))
user = db.session.get(Student, session['user_id'])
user.name = request.form.get('name')
user.bio = request.form.get('bio')
user.education = request.form.get('education')
user.skills = request.form.get('skills')
user.whatsapp_link = request.form.get('whatsapp_link')
if 'profile_pic' in request.files:
file = request.files['profile_pic']
if file and file.filename != '':
# Upload directly to Cloudinary and save the URL
upload_result = cloudinary.uploader.upload(file, folder="skillsync/students/")
user.profile_pic = upload_result['secure_url']
db.session.commit()
session['name'] = user.name
return redirect(url_for('student_feed'))
@app.route('/edit-recruiter-profile', methods=['POST'])
def edit_recruiter_profile():
if 'user_id' not in session or session['role'] != 'recruiter':
return redirect(url_for('login'))
user = Recruiter.query.get(session['user_id'])
user.name = request.form.get('name')
user.company_name = request.form.get('company')
user.phone = request.form.get('phone')
user.website = request.form.get('website')
user.position = request.form.get('position')
if 'profile_pic' in request.files:
file = request.files['profile_pic']
if file and file.filename != '':
upload_result = cloudinary.uploader.upload(file, folder="skillsync/recruiters/")
user.profile_pic = upload_result['secure_url']
db.session.commit()
session['name'] = user.name
return redirect(url_for('recruiter_dashboard'))
# --- 7. UTILITIES ---
@app.route('/delete-comment/<int:comment_id>')
def delete_comment(comment_id):
if 'user_id' not in session:
return redirect(url_for('login'))
comment = Comment.query.get_or_404(comment_id)
# Check if the current user is the author of the comment
if comment.author_id == session['user_id']:
db.session.delete(comment)
db.session.commit()
flash("Comment deleted.", "success")
return redirect(request.referrer)
@app.route('/clear-notifications')
def clear_notifications():
if 'user_id' in session:
# Mark all as read for this specific user and role
Notification.query.filter_by(
recipient_id=session['user_id'],
recipient_role=session['role'],
is_read=False
).update({"is_read": True})
db.session.commit()
return jsonify({"status": "success"})
return jsonify({"status": "unauthorized"}), 401
@app.route('/submit-report', methods=['POST'])
def submit_report():
print("--- DEBUG REPORT SUBMISSION ---")
print(f"User ID in Session: {session.get('user_id')}")
print(f"Role in Session: {session.get('role')}") # <--- This MUST say 'student' or 'recruiter'
if 'user_id' not in session:
print("ERROR: User ID missing, redirecting to login.")
return redirect(url_for('login'))
message_content = request.form.get('message')
sender_name = session.get('name')
sender_role = session.get('role', 'student') # Default to student if missing
if message_content:
try:
new_report = Report(
sender_name=sender_name,
sender_role=sender_role,
message=message_content
)
db.session.add(new_report)
db.session.commit()
print("SUCCESS: Report written to database.")
# Keep session alive
session.modified = True
except Exception as e:
db.session.rollback()
print(f"DATABASE ERROR: {e}")
if session.get('role') == 'student':
return redirect(url_for('student_feed'))
elif session.get('role') == 'recruiter':
return redirect(url_for('recruiter_dashboard'))
else:
return redirect(url_for('home'))
# --- 8. API ROUTES (For Search & Popups) ---
@app.route('/api/search')
def api_search():
query = request.args.get('query', '').lower()
search_type = request.args.get('type', 'all')
results = {'people': [], 'internships': []}
if not query: return jsonify(results)
if search_type in ['all', 'people']:
students = Student.query.filter(Student.name.ilike(f'%{query}%')).limit(5).all()
recruiters = Recruiter.query.filter(Recruiter.name.ilike(f'%{query}%')).limit(5).all()
for s in students:
results['people'].append({'id': s.student_id, 'name': s.name, 'role': 'student'})
for r in recruiters:
results['people'].append({'id': r.recruiter_id, 'name': r.name, 'role': 'recruiter'})
if search_type in ['all', 'internships']:
posts = Post.query.filter(Post.can_apply == True, Post.content.ilike(f'%{query}%')).limit(5).all()
for p in posts:
results['internships'].append({'id': p.id, 'title': p.content[:30] + "..."})
return jsonify(results)
# Add this near your other UTILITIES routes in app.py
@app.route('/api/user-details/<role>/<int:user_id>')
def get_user_details(role, user_id):
if role == 'student':
user = Student.query.get(user_id)
if not user: return jsonify({"error": "Not found"}), 404
return jsonify({
"name": user.name,
"email": user.email,
"education": user.education or "Not specified",
"skills": user.skills or "",
"profile_pic": user.profile_pic,
"whatsapp": user.whatsapp_link or ""
})
else:
user = Recruiter.query.get(user_id)
if not user: return jsonify({"error": "Not found"}), 404
return jsonify({
"name": user.name,
"email": user.email,
"company_name": user.company_name or "Independent",
"status": "Verified Partner" if getattr(user, 'is_verified', False) else "Standard Recruiter",
"facebook": user.facebook or "",
"twitter": user.twitter or "",
"website": user.website or "",
"profile_pic": user.profile_pic,
"position": user.position or ""
})
# --- NEW MASTER AI CONFIG ---
YOUTUBE_API_KEY = "AIzaSyDeT5dueyBjrcUp1fDdQFmCa5Gnc58rbtQ"
# Get your free key at apilayer.com (Skills API)
SKILLS_API_KEY = "nKpSaFqgGRNiKeVmj2euz0TU9JqOrVrd"
def extract_skills_pro(text_content):
url = "https://api.apilayer.com/skills/extract"
headers = {"apikey": "nKpSaFqgGRNiKeVmj2euz0TU9JqOrVrd"}
try:
response = requests.post(url, headers=headers, data=text_content.encode("utf-8"))
if response.status_code == 200:
return [s['skill'].lower() for s in response.json()]
except:
pass
# --- 100+ KEYWORD IT DATABASE ---
it_keywords = [
# Languages
"python", "javascript", "typescript", "java", "c++", "c#", "rust", "go", "ruby", "php", "swift", "kotlin", "dart", "scala", "perl", "bash", "powershell", "r language", "solidity", "objective-c",
# Web Frontend
"react", "next.js", "angular", "vue", "svelte", "tailwind", "bootstrap", "three.js", "html5", "css3", "sass", "jquery", "webpack", "vite", "redux", "zustand", "webassembly", "responsive design",
# Backend & Frameworks
"node", "express", "django", "flask", "fastapi", "spring boot", "laravel", "rails", "asp.net", "nest.js", "graphql", "rest api", "microservices", "socket.io", "grpc",
# AI & Data Science
"machine learning", "deep learning", "nlp", "tensorflow", "pytorch", "pandas", "numpy", "scikit-learn", "langchain", "agentic ai", "llm", "vector databases", "tableau", "powerbi", "opencv", "data visualization", "data science", "data structures", "algorithms",
# Cloud & DevOps
"aws", "azure", "google cloud", "gcp", "docker", "kubernetes", "terraform", "ansible", "jenkins", "ci/cd", "linux", "nginx", "github actions", "prometheus", "grafana", "cloud computing", "serverless",
# Databases
"sql", "postgresql", "mysql", "mongodb", "redis", "firebase", "cassandra", "oracle", "sqlite", "elasticsearch", "dynamodb", "snowflake",
# Mobile & UI/UX
"flutter", "react native", "swiftui", "figma", "ui/ux", "adobe xd", "android studio", "ios development", "mobile development",
# Cybersecurity
"ethical hacking", "penetration testing", "wireshark", "nmap", "owasp", "cryptography", "network security", "firewall", "siem", "cybersecurity",
# Industry Tools & Systems
"git", "github", "bitbucket", "jira", "agile", "scrum", "system design", "unit testing", "playwright", "cypress", "postman", "blockchain", "web3", "iot", "internet of things", "rpa", "edge computing"
]
# --- MATCHING LOGIC ---
# We use a case-insensitive boundary search to ensure 'Java' doesn't match 'JavaScript'
text_lower = text_content.lower()
found = []
# We use a single regex join for speed (highly recommended for 100+ keywords)
pattern = re.compile(r'\b(' + '|'.join(re.escape(word) for word in it_keywords) + r')\b')
matches = pattern.findall(text_lower)
# Return unique found skills
return list(set(matches))
def get_master_ai_recommendations(user_skills):
# 1. ANALYZE MARKET (What recruiters want)
all_posts = Post.query.filter_by(can_apply=True).all()
market_text = " ".join([p.content for p in all_posts])
market_skills = Counter(extract_skills_pro(market_text))
# 2. ANALYZE PEERS (Competitive Benchmarking)
all_students = Student.query.all()
peer_skills_text = " ".join([(s.skills or "") for s in all_students])
peer_skills_list = extract_skills_pro(peer_skills_text)
peer_popularity = Counter(peer_skills_list)
# 3. USER GAP ANALYSIS
user_skills_clean = [s.strip().lower() for s in (user_skills or "").split(',')]
recommendations = []
youtube = build('youtube', 'v3', developerKey=YOUTUBE_API_KEY)
# Logic: If skill is in demand OR peers have it, and user DOESN'T have it
all_relevant_skills = set(list(market_skills.keys()) + list(peer_popularity.keys()))
for skill in all_relevant_skills:
if skill not in user_skills_clean:
# Determine if this is a "Competitive Gap" (many peers have it)
peer_count = peer_popularity.get(skill, 0)
is_competitive = peer_count > (len(all_students) * 0.2) # 20% threshold
reason = "Competitive Threat" if is_competitive else "Market Demand"
search_q = f"{skill} mastery tutorial 2026 for developers"
try:
search_response = youtube.search().list(
q=search_q,
part='snippet',
maxResults=1,
type='video'
).execute()
for item in search_response['items']:
recommendations.append({
"skill": f"{skill.upper()} ({reason})",
"title": item['snippet']['title'],
"url": f"https://www.youtube.com/watch?v={item['id']['videoId']}",
"thumbnail": item['snippet']['thumbnails']['medium']['url']
})
except: continue
if len(recommendations) >= 50: break # Limit to 4 to save API quota
return recommendations
@app.route('/skill-development')
def skill_development():
if 'user_id' not in session or session.get('role') != 'student':
return redirect(url_for('login'))
student_id = session['user_id']
user = db.session.get(Student, session['user_id'])
# 1. Check if we already have resources saved
resources = SkillResource.query.filter_by(student_id=student_id).all()
# 2. ONLY run AI if there are no resources (first time)
if not resources:
ai_results = get_master_ai_recommendations(user.skills or "")
for rec in ai_results:
new_res = SkillResource(
student_id=student_id,
title=rec['title'],
link=rec['url'],
thumbnail=rec['thumbnail'],
category=rec['skill']
)
db.session.add(new_res)
db.session.commit()
# Refresh the resources list after adding
resources = SkillResource.query.filter_by(student_id=student_id).all()
# 3. Notification Logic (Remains fast)
notifications = Notification.query.filter_by(
recipient_id=student_id,
recipient_role='student'
).order_by(Notification.date_created.desc()).limit(10).all()
unread_count = Notification.query.filter_by(
recipient_id=student_id,
recipient_role='student',
is_read=False
).count()
return render_template('skill_development.html',
user=user,
resources=resources,
notifications=notifications,
unread_count=unread_count)
def get_match_score(student_skills, post_content):
if not student_skills: return 0
# Use your AI logic to see what the post needs
required = extract_skills_pro(post_content)
if not required: return 0
student_list = [s.strip().lower() for s in student_skills.split(',')]
matches = [s for s in required if s.lower() in student_list]
# Calculate percentage
score = (len(matches) / len(required)) * 100
return round(score)
@app.context_processor
def inject_sidebar_data():
"""
SkillSync Master Context Processor:
Provides 'market_trends' and 'top_students' to all templates.
"""
try:
# --- 1. MARKET TRENDS LOGIC ---
# Fetch all posts to see what skills recruiters are mentioning
all_posts = Post.query.all()
skill_tally = Counter()
for post in all_posts:
# Uses your existing extract_skills_pro function
found_skills = extract_skills_pro(post.content)
if found_skills:
for skill in found_skills:
skill_tally[skill] += 1
# Get the top 7 most mentioned skills for the "Trends" cloud
top_trends = skill_tally.most_common(7)
# --- 2. TOP STUDENTS RANKING LOGIC ---
all_students = Student.query.all()
student_scores = []
for s in all_students:
# Clean and split the comma-separated skills string from your Student model
# e.g., "Python, Flask, React" -> ['python', 'flask', 'react']
skill_list = [sk.strip() for sk in (s.skills or "").split(',') if sk.strip()]
student_scores.append({
'name': s.name,
'skill_count': len(skill_list),
'profile_pic': s.profile_pic,
'id': s.student_id,
'top_skills': skill_list[:2] # Optional: grab first 2 for a small preview
})
# Sort students by skill_count in descending order (highest first)
# We take the top 5 for the sidebar ranking
ranked_students = sorted(student_scores, key=lambda x: x['skill_count'], reverse=True)[:5]
return dict(
market_trends=top_trends,
top_students=ranked_students
)
except Exception as e:
# Log the error to your terminal but don't crash the website
print(f"CRITICAL SIDEBAR ERROR: {e}")
return dict(market_trends=[], top_students=[])
@app.route('/refresh-skills')
def refresh_ai():
if 'user_id' in session and session.get('role') == 'student':
student_id = session['user_id']
# Only delete when explicitly asked
SkillResource.query.filter_by(student_id=student_id).delete()
db.session.commit()
return redirect(url_for('skill_development'))
@app.route('/apply/<int:post_id>')
def apply_internship(post_id):
if 'user_id' not in session or session.get('role') != 'student':
flash("Please log in as a student to apply.", "warning")
return redirect(url_for('login'))
# 1. Fetch data
post = Post.query.get_or_404(post_id)
student = Student.query.get(session['user_id'])
recruiter = Recruiter.query.get(post.author_id)
if not student:
flash("Student profile not found.", "danger")
return redirect(url_for('student_feed'))
# 2. Prevent duplicate applications
existing_app = Application.query.filter_by(
post_id=post.id,
student_id=student.student_id
).first()
if existing_app:
flash("You have already applied for this internship.", "info")
return redirect(url_for('student_feed'))
# 3. Create Objects
new_app = Application(
post_id=post.id,
student_id=student.student_id,
recruiter_id=recruiter.recruiter_id if recruiter else None
)
db.session.add(new_app)
# 4. Save and Notify (MATCHING YOUR MODEL)
try:
if recruiter:
new_notification = Notification(
recipient_id=recruiter.recruiter_id,
recipient_role='recruiter', # Matches your model column name
sender_name=student.name, # Added this to match your model
message=f"applied for your internship: {post.content[:30]}...",
is_read=False
)
db.session.add(new_notification)
db.session.commit() # Now it saves both correctly
# 5. Email Logic
if recruiter and recruiter.email:
msg = Message(
subject=f"SkillSync Application: {student.name}",
sender=app.config.get('MAIL_USERNAME'),
recipients=[recruiter.email],
body=f"Hello {recruiter.name},\n\n{student.name} has applied for your internship."
)
mail.send(msg)
flash("Success! Application sent and recruiter notified.", "success")
else:
flash("Applied successfully!", "success")
except Exception as e:
db.session.rollback()
print(f"Error: {e}")
flash("An error occurred. Please try again.", "danger")
return redirect(url_for('student_feed'))
@app.route('/recruiter/applications')
def view_applications():
# 1. Access Control
if 'user_id' not in session or session.get('role') != 'recruiter':
flash("Please log in as a recruiter.", "warning")
return redirect(url_for('login'))
recruiter_id = session['user_id']
# 2. Fetch Header Data (Crucial for 0 errors in header rendering)
user = db.session.get(Recruiter, recruiter_id)
if not user:
flash("Recruiter profile not found.", "danger")
return redirect(url_for('login'))
# Fetch Notifications for the header bell icon
notifications = Notification.query.filter_by(
recipient_id=recruiter_id,
recipient_role='recruiter'
).order_by(Notification.date_created.desc()).limit(10).all()
unread_count = Notification.query.filter_by(
recipient_id=recruiter_id,
recipient_role='recruiter',
is_read=False
).count()
# 3. Fetch Application Data
# Get all applications where the recruiter_id matches the logged-in user
apps = Application.query.filter_by(recruiter_id=recruiter_id).all()
applied_students = []
for app_entry in apps:
student = Student.query.get(app_entry.student_id)
post = Post.query.get(app_entry.post_id)
if student and post:
# Calculate AI Match Score
try:
# Assuming get_match_score(student_skills_str, post_content_str) exists
score = get_match_score(student.skills or "", post.content or "")
except Exception as e:
print(f"Match calculation error: {e}")
score = 0 # Fallback score
applied_students.append({
'student': student,
'post_content': post.content,
'score': score,
'date': app_entry.date_applied
})
# 4. Sort by highest AI score first
applied_students = sorted(applied_students, key=lambda x: x['score'], reverse=True)
# 5. Render Template with all required header variables
return render_template(
'application.html',
user=user,
user_name=user.name,
user_role='recruiter',
notifications=notifications,
unread_count=unread_count,
applications=applied_students
)
'''@app.route('/setup-admin')
def setup_admin():
# Only create if no admin exists
if Admin.query.count() == 0:
admin = Admin(
name="Super Admin",
email="admin@skillsync.com",
password="admin123" # Change this to a secure password
)
db.session.add(admin)
db.session.commit()
return "Admin account created! You can now log in at /login."
return "Admin already exists."'''
if __name__ == '__main__':
# Railway provides the port via an environment variable
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)