-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdepartmentDatabase.py
44 lines (31 loc) · 1.48 KB
/
departmentDatabase.py
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
from databaseConfig.dbConnection import Database
class DepartmentDB(Database):
# This class was created to save all the departments
# present in UnB
@staticmethod
def savedepartment(departments):
# This static method the department list and save
# it in database Mongodb
# Get the instance from database connection
db = Database.defineConnections()
collection_department = db['departments']
old_size_list = 0
# Run for all the department list
for campus, department_list in departments.items():
print("Saving departments for campus {}...".format(campus))
# How it comes with the entire list having all the departaments,
# we split the list according with the campus
size_list = len(department_list)
department_set = department_list[old_size_list: size_list]
old_size_list = size_list
# After the split get the current attributes and
# save all of then in Mongo
for department in department_set:
current_department = {
'campus': department.getCampus(),
'code': department.getCode(),
'name': department.getName(),
'initials': department.getInitials(),
'disciplines': [x.getCode() for x in department.getDisciplines()]
}
collection_department.insert_one(current_department)