-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
71 lines (52 loc) · 1.95 KB
/
run.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
from modules.faltas import *
from modules.templates import *
import requests
def get_session_and_index(data):
print("\nLogando no moodle...")
try:
session = requests.Session()
# pegando logintoken
soup = parse_html(session, "https://lms.infnet.edu.br/moodle/login/index.php")
token = soup.find("input", {"name": "logintoken"}).attrs["value"]
payload = {
"username": data["username"],
"password": data["password"],
"logintoken": token
}
res = get_res(session.post("https://lms.infnet.edu.br/moodle/login/index.php", payload))
# se achar o campo de logintoken nao foi efetuado o login
if res.find("input", {"name": "logintoken"}) is not None:
print("Erro na autenticação! Por favor tente novamente.\n")
exit(-1)
return session, res
except:
print("Parece que o moodle esta fora do ar :/")
print("Por favor tente novamente mais tarde")
exit(-1)
def run():
data = get_data()
cache = get_cache()
template = get_template(data)
if template:
print("\nDados do template:")
print(f"Escola: {template['escola']}")
print(f"Curso: {template['curso']}")
print(f"Classe: {template['classe']}")
print(f"Bloco: {template['bloco']}")
# logando...
session, index_page = get_session_and_index(data)
if not template:
escola = get_escola(index_page)
curso = get_curso(index_page, escola)
classe = get_classe(index_page, curso)
bloco = get_bloco(index_page, classe)
materia = get_materia(index_page, bloco)
materia_datas = get_materia_data(materia)
ask_save_template(escola, curso, classe, bloco, materia_datas, data)
else:
materia_datas = template["materias"]
get_faltas(session, materia_datas, cache)
save_data(data)
session.close()
if __name__ == "__main__":
run()