-
Notifications
You must be signed in to change notification settings - Fork 1
/
mwscanner.py
80 lines (50 loc) · 2.21 KB
/
mwscanner.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
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
from multiprocessing.pool import ThreadPool
from mwscanner.builders.CampusBuilder import CampusBuilder
from mwscanner.Campus import Campus
from databaseConfig.SaveDataFacade import SaveDataFacade
BASE_URL = 'https://matriculaweb.unb.br/'
def proccessHabilitations(campus: Campus):
all_habilitations = []
for index, course in enumerate(campus.getCourses()):
for habilitation in course.getHabilitations():
all_habilitations.append(habilitation)
return all_habilitations
def proccessDisciplines(campus: Campus):
all_disciplines = []
# prints department information
# and then build the list of disciplines that each department have
for index, department in enumerate(campus.getDepartments()):
for discipline in department.getDisciplines():
all_disciplines.append(discipline)
return all_disciplines
if __name__ == '__main__':
try:
t_pool = ThreadPool(processes=2)
# creates a campus object, it will hold
# information about the campi on the Matricula Web
campus = CampusBuilder().buildCampus()
# call methodes to scrap courses and departments information
# frow the Web
list_all_campus_courses = t_pool.apply_async(
campus.getAllCampusCourses)
list_all_campus_departments = t_pool.apply_async(
campus.getAllCampusDepartments)
list_all_campus_courses = list_all_campus_courses.get()
list_all_campus_departments = list_all_campus_departments.get()
# get habilitations and disciplines
list_all_habilitations = t_pool.apply_async(
proccessHabilitations, (campus, ))
list_all_disciplines = t_pool.apply_async(
proccessDisciplines, (campus, ))
list_all_habilitations = list_all_habilitations.get()
list_all_disciplines = list_all_disciplines.get()
t_pool.terminate()
print("Calling db save function...")
SaveDataFacade.saveData(
list_all_campus_courses,
list_all_campus_departments,
list_all_habilitations,
list_all_disciplines
)
except KeyboardInterrupt:
print('Interruption')