-
Notifications
You must be signed in to change notification settings - Fork 0
/
lecture_browser.py
39 lines (31 loc) · 1.26 KB
/
lecture_browser.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
from login_session import LoginSession
from lecture import Lecture
from bs4 import BeautifulSoup
class LectureBrowser:
HOST = "eclass.seoultech.ac.kr"
PATH_TODOLIST = "/ilos/mp/todo_list.acl"
def __init__(self, login: LoginSession):
self.login = login
def get_lectures(self):
lectures: list[Lecture] = []
res = self.login.session.get(f"https://{self.login.HOST}{self.PATH_TODOLIST}")
soup = BeautifulSoup(res.text, "html.parser")
todo_wraps = soup.find_all("div", {"class": "todo_wrap"})
for todo in todo_wraps:
onclick = todo.get("onclick")
if onclick is not None:
class_id, lecture_id, todo_type = onclick.split("'")[1::2]
if todo_type == "lecture_weeks":
lectures.append(
Lecture(
class_id=class_id, lecture_id=lecture_id, login=self.login
)
)
return lectures
if __name__ == "__main__":
from login_session import LoginSession
with LoginSession() as login:
browser = LectureBrowser(login)
lectures = browser.get_lectures()
for lecture in lectures:
print(lecture.class_name, lecture.times)