/
api.py
115 lines (94 loc) · 4.04 KB
/
api.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
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
from selenium import webdriver
from time import sleep
from bs4 import BeautifulSoup
class Chrome:
def __init__(self, user, password):
self.user = user
self.password = password
self.drive_path = "chromedriver.exe"
self.options = webdriver.ChromeOptions()
self.options.add_argument('user-data-dir=Perfil')
self.chrome = webdriver.Chrome(
self.drive_path,
options=self.options
)
self.matricula = [[], [], []]
self.horario = [["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"], []]
self.att = []
self.desc = []
def acess(self):
self.chrome.get("https://sigaa.ufma.br/sigaa/verTelaLogin.do")
def exit(self):
self.chrome.quit()
def getHour(self):
try:
input_user = self.chrome.find_element_by_id('usuarioLogin')
input_pass = self.chrome.find_element_by_id('senhaLogin')
btn_login = self.chrome.find_element_by_class_name('botao-entrar')
input_user.send_keys(self.user)
input_pass.send_keys(self.password)
btn_login.click()
btn_skip1 = self.chrome.find_element_by_name('j_id_jsp_712183460_1:j_id_jsp_712183460_2')
btn_skip1.click()
sleep(8)
btn_skip1 = self.chrome.find_element_by_name('j_id_jsp_712183460_1:j_id_jsp_712183460_2')
btn_skip1.click()
sleep(5)
btn_show_menu = self.chrome.find_element_by_id('menu:formensino:menuensino')
btn_show_menu.click()
btn_matricula = self.chrome.find_element_by_id('menu:formensino:atestadoMatricula')
btn_matricula.click()
"""PEGANDO OS DADOS DA TABELA MATRICULA"""
table = self.chrome.find_element_by_id('matriculas')
data = table.get_attribute('innerHTML')
html = BeautifulSoup(data, 'html.parser')
"""PEGANDO O CODIGO DAS MATERIAS"""
info_codigo = html.select('.codigo')
for i in info_codigo:
self.matricula[0].append(i.text)
"""PEGANDO O NOME DAS MATERIAS"""
info_name = html.select('.componente')
for i in info_name:
self.matricula[1].append(i.text)
"""PEGANDO O DOCENTE DA MATERIA"""
info_doc = html.select('.docente')
for i in info_doc:
self.matricula[2].append(i.text)
"""PEGANDO OS DADOS DA TABELA HORARIO"""
table1 = self.chrome.find_element_by_id('horario')
data1 = table1.get_attribute('innerHTML')
html1 = BeautifulSoup(data1, 'html.parser')
tr = self.chrome.find_elements_by_xpath("//table[@id='horario']/tbody/tr/td")
all_schedules = []
for i in tr:
a = i.get_attribute('innerHTML')
b = BeautifulSoup(a, 'html.parser')
c = b.span
if not c == None:
all_schedules.append(html1.find(id=c['id']).text)
print(all_schedules)
self.chrome.get("https://sigaa.ufma.br/sigaa/portais/discente/discente.jsf")
except Exception as error:
print(error)
def getAtv(self):
path_att = self.chrome.find_elements_by_xpath("//td[@headers='atividades_data']")
path_desc_att = self.chrome.find_elements_by_xpath("//td[@headers='descricao-atividade']")
for i in path_att:
a = BeautifulSoup(i.get_attribute('innerHTML'), 'html.parser').text.rsplit('\t')
a = ''.join(a)
b = a.rsplit('\n')
b = ''.join(b)
self.att.append(b)
for i in path_desc_att:
a = BeautifulSoup(i.get_attribute('innerHTML'), 'html.parser').text.rsplit('\t')
a = ''.join(a)
b = a.rsplit('\n')
b = ''.join(b)
self.desc.append(b)
print(self.att)
print(self.desc)
if __name__ == "__main__":
chrome = Chrome('nome.sobrenome', 'senha')
chrome.acess()
chrome.getHour()
chrome.getAtv()