roshcheeku commited on
Commit
966edc1
·
verified ·
1 Parent(s): 86d410f

Create seed.py

Browse files
Files changed (1) hide show
  1. seed.py +35 -0
seed.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # seed.py
2
+ from db import db
3
+ import bcrypt
4
+ from bson.objectid import ObjectId
5
+
6
+ def create_admin():
7
+ email = "admin@example.com"
8
+ if db.users.find_one({"email": email}):
9
+ print("Admin exists")
10
+ return
11
+ hashed = bcrypt.hashpw("Admin123!".encode(), bcrypt.gensalt()).decode()
12
+ db.users.insert_one({
13
+ "name":"Admin",
14
+ "email": email,
15
+ "password": hashed,
16
+ "role": "admin",
17
+ "blocked": False
18
+ })
19
+ print("Admin created: admin@example.com / Admin123!")
20
+
21
+ def create_courses():
22
+ courses = [
23
+ {"title":"Data Structures", "code":"CS201"},
24
+ {"title":"Operating Systems", "code":"CS301"},
25
+ {"title":"Database Systems", "code":"CS303"},
26
+ {"title":"Machine Learning", "code":"CS405"}
27
+ ]
28
+ for c in courses:
29
+ if not db.courses.find_one({"title": c["title"]}):
30
+ db.courses.insert_one(c)
31
+ print("Seeded courses")
32
+
33
+ if __name__ == "__main__":
34
+ create_admin()
35
+ create_courses()