-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimetable.py
126 lines (90 loc) · 3.3 KB
/
timetable.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
116
117
118
119
120
121
122
123
124
125
126
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from time import sleep
import sys
import csv
def getallunits(driver):
allclass = driver.find_elements_by_xpath("//select[@name='criteriaEntry:allUnits']/option")
units = []
for elm in allclass:
split = elm.text.split(" ", 1)
unit = (elm.get_attribute("value"), split[0], split[1] )
units.append(unit)
print(units)
print(units , file=sys.stderr)
return units
def blankandsearch(driver):
driver.get("http://timetable.student.curtin.edu.au/criteriaEntry.jsf")
assert "Plan Your Timetable" in driver.title
#clear search
elem = driver.find_element_by_name("criteriaEntry:filterUnitCodeOrTitle")
elem.clear()
#elem.send_keys("pycon")
#elem.send_keys(Keys.RETURN)
#assert "No results found." not in driver.page_source
#search for all units
srch = driver.find_element_by_name("criteriaEntry:unitSearchButton")
srch.click()
def viewtimetable(driver, classcode):
#driver = webdriver.Firefox()
#driver = webdriver.Firefox(options=options)
driver.get("http://timetable.student.curtin.edu.au/criteriaEntry.jsf")
assert "Plan Your Timetable" in driver.title
#clear all units
clear = driver.find_element_by_name("criteriaEntry:removeAllButton")
clear.click()
#select a unit
rndclass = driver.find_element_by_xpath("//option[@value=" + classcode[0] + "]")
rndclass.click()
#add unit
add = driver.find_element_by_name("criteriaEntry:addButton")
add.click()
#view timetable
view = driver.find_element_by_name("criteriaEntry:timetableForUnitsButton")
view.click()
def getdata(driver, csv):
#get time table
classtimetable = driver.find_elements_by_xpath("//table[@class='unitList']/tbody/tr")
#classtimetable = driver.find_element_by_class_name("unitList")
#print(classtimetable.text)
for i in classtimetable:
#print(i.text)
#for j in i.find_elements_by_tag_name("td"):
# print(j.text)
comp_list = [j.text for j in i.find_elements_by_tag_name("td")]
print(comp_list)
print(comp_list , file=sys.stderr)
csv.writerow(comp_list)
def main():
options = Options()
#options.headless = True
driver = webdriver.Firefox(options=options)
blankandsearch(driver)
units = getallunits(driver)
sleep(5)
with open('units.csv', 'wt') as f:
csv_writer = csv.writer(f)
total = len(units)
progress = 1
for i in units:
# if (progress < 1116):
# progress = progress + 1
# continue
for count in range(3):
print("grabbing " + str(i[:]) + " " + str(progress) + " out of " + str(total) , file=sys.stderr)
try:
viewtimetable(driver, i)
getdata(driver, csv_writer)
break
except:
driver.close()
sleep(10)
driver = webdriver.Firefox(options=options)
blankandsearch(driver)
# driver.close()
#sleep(3)
progress = progress + 1
driver.close()
if __name__ == "__main__":
main()