-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
175 lines (155 loc) · 6.16 KB
/
Copy pathmain.py
File metadata and controls
175 lines (155 loc) · 6.16 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
import mysql.connector
from mysql.connector import Error
import uuid
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Connection settings
HOST = os.getenv('host')
USER = os.getenv('user')
PASSWORD = os.getenv('password')
DATABASE = os.getenv('database')
def create_connection():
"""Create a database connection"""
try:
connection = mysql.connector.connect(
host=HOST, # Update with your database host
user=USER, # Update with your database username
password=PASSWORD, # Update with your database password
database=DATABASE
)
if connection.is_connected():
print("Connection to MySQL DB successful")
return connection
except Error as e:
print(f"The error '{e}' occurred")
return None
def execute_query(connection, query, data):
"""Execute a single query"""
cursor = connection.cursor()
try:
cursor.execute(query, data)
connection.commit()
print("Query executed successfully")
except Error as e:
print(f"The error '{e}' occurred")
def insert_data():
connection = create_connection()
if connection is None:
return
# Inserting data into STUDENTS table
students_query = """
INSERT INTO STUDENTS (ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE, COURSE, EDUCATIONAL_DEGREE, SPECIALITY, ACTIVE)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
"""
students_data = [
(str(uuid.uuid4()), 'John', 'Doe', 'john.doe@example.com', '1234567890', 1, 'Bachelor', 'Computer Science',
True),
(str(uuid.uuid4()), 'Jane', 'Smith', 'jane.smith@example.com', '0987654321', 2, 'Master', 'Mathematics', True)
# Add more student records as needed
]
for data in students_data:
execute_query(connection, students_query, data)
# Inserting data into ROOMS table
rooms_query = """
INSERT INTO ROOMS (ID, BUILDING, FLOOR, NUMBER, DISPLAY_NAME, SEATS_NUMBER)
VALUES (%s, %s, %s, %s, %s, %s)
"""
rooms_data = [
(str(uuid.uuid4()), 'Building A', 1, 101, 'Room 101', 30),
(str(uuid.uuid4()), 'Building B', 2, 202, 'Room 202', 50)
# Add more room records as needed
]
for data in rooms_data:
execute_query(connection, rooms_query, data)
# Inserting data into COURSES table
courses_query = """
INSERT INTO COURSES (ID, COURSE_DISPLAY_SHORT_NAME, COURSE_DISPLAY_FULL_NAME, COURSE_DESCRIPTION, LECTURES_NUM, PRACTICES_NUM)
VALUES (%s, %s, %s, %s, %s, %s)
"""
courses_data = [
(str(uuid.uuid4()), 'CS101', 'Introduction to Computer Science', 'Basic concepts of computer science', 30, 15),
(str(uuid.uuid4()), 'MATH201', 'Advanced Mathematics', 'In-depth study of advanced mathematical concepts', 25,
10)
# Add more course records as needed
]
for data in courses_data:
execute_query(connection, courses_query, data)
# Inserting data into INSTRUCTORS table
instructors_query = """
INSERT INTO INSTRUCTORS (ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE, ACTIVE)
VALUES (%s, %s, %s, %s, %s, %s)
"""
instructors_data = [
(str(uuid.uuid4()), 'Alice', 'Johnson', 'alice.johnson@example.com', '1122334455', True),
(str(uuid.uuid4()), 'Bob', 'Williams', 'bob.williams@example.com', '5544332211', True)
# Add more instructor records as needed
]
for data in instructors_data:
execute_query(connection, instructors_query, data)
# Inserting data into LESSONS_SCHEDULE table
lessons_schedule_query = """
INSERT INTO LESSONS_SCHEDULE (ID, START_TIME, END_TIME)
VALUES (%s, %s, %s)
"""
lessons_schedule_data = [
(1, '08:00:00', '09:00:00'),
(2, '09:00:00', '10:00:00')
# Add more lesson schedule records as needed
]
for data in lessons_schedule_data:
execute_query(connection, lessons_schedule_query, data)
# Inserting data into INSTRUCTORS_COURSES table
instructors_courses_query = """
INSERT INTO INSTRUCTORS_COURSES (INSTRUCTOR_ID, COURSE_ID)
VALUES (%s, %s)
"""
instructors_courses_data = [
(instructors_data[0][0], courses_data[0][0]),
(instructors_data[1][0], courses_data[1][0])
# Add more instructor-course relationships as needed
]
for data in instructors_courses_data:
execute_query(connection, instructors_courses_query, data)
# Inserting data into STUDENTS_COURSE_GROUPS table
students_course_groups_query = """
INSERT INTO STUDENTS_COURSE_GROUPS (ID, COURSE_ID)
VALUES (%s, %s)
"""
students_course_groups_data = [
(str(uuid.uuid4()), courses_data[0][0]),
(str(uuid.uuid4()), courses_data[1][0])
# Add more student course group records as needed
]
for data in students_course_groups_data:
execute_query(connection, students_course_groups_query, data)
# Inserting data into STUDENTS_COURSE_GROUP_STUDENTS table
students_course_group_students_query = """
INSERT INTO STUDENTS_COURSE_GROUP_STUDENTS (STUDENT_ID, GROUP_ID)
VALUES (%s, %s)
"""
students_course_group_students_data = [
(students_data[0][0], students_course_groups_data[0][0]),
(students_data[1][0], students_course_groups_data[1][0])
# Add more student-group relationships as needed
]
for data in students_course_group_students_data:
execute_query(connection, students_course_group_students_query, data)
# Inserting data into SCHEDULE table
schedule_query = """
INSERT INTO SCHEDULE (ID, COURSE_ID, INSTRUCTOR_ID, STUDENTS_COURSE_GROUP_ID, WEEK_DAY, LESSON_SCHEDULE_ID, ROOM_ID)
VALUES (%s, %s, %s, %s, %s, %s, %s)
"""
schedule_data = [
(1, courses_data[0][0], instructors_data[0][0], students_course_groups_data[0][0], 'Monday', 1,
rooms_data[0][0]),
(2, courses_data[1][0], instructors_data[1][0], students_course_groups_data[1][0], 'Tuesday', 2,
rooms_data[1][0])
# Add more schedule records as needed
]
for data in schedule_data:
execute_query(connection, schedule_query, data)
connection.close()
if __name__ == "__main__":
insert_data()