-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadCourses.py
More file actions
45 lines (37 loc) · 1.63 KB
/
DownloadCourses.py
File metadata and controls
45 lines (37 loc) · 1.63 KB
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
"""
a module to download all courses from the uottawa course timetable website
much more minimized version of https://github.com/morinted/schedule-generator
"""
from concurrent.futures.thread import ThreadPoolExecutor
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import Select
def main(term="ALL"):
"""main"""
courses = []
driver = webdriver.Chrome()
driver.get("https://web30.uottawa.ca/v3/SITS/timetable/Search.aspx")
dropdown = Select(driver.find_element(By.ID, "ctl00_MainContentPlaceHolder_Basic_TermDropDown"))
dropdown.select_by_value(term)
driver.find_element(By.NAME, "ctl00$MainContentPlaceHolder$Basic_Button").click()
assert "Course Timetable" in driver.title
next_btn = driver.find_element(By.LINK_TEXT, "Next")
while next_btn:
course_links = driver.find_elements(By.CSS_SELECTOR, ".CourseCode>a")
for course_link in course_links:
courses.append(course_link.text + " " +
course_link.get_attribute("href"))
next_btn.click()
try:
next_btn = driver.find_element(By.LINK_TEXT, "Next")
except NoSuchElementException:
break
driver.close()
courses.sort()
with open("courses"+term+".txt", "w") as course_file:
course_file.writelines("number of links:" + str(len(courses)) + "\n")
course_file.writelines("\n".join(courses))
with ThreadPoolExecutor(max_workers=5) as executer:
for term in ["2185", "2189", "2191"]:
executer.submit(main, term)