-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenter_edoz_grades.py
More file actions
62 lines (53 loc) · 1.99 KB
/
Copy pathenter_edoz_grades.py
File metadata and controls
62 lines (53 loc) · 1.99 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
Enter grades into edoz.
"""
from __future__ import print_function
import sys
import argparse
from selenium import webdriver
# constants
EDOZ_URL='https://www.lehrbetrieb.ethz.ch/edoz/loginPre.do?lang=en'
# parameters
parser = argparse.ArgumentParser(description="Enter grades into edoz.")
parser.add_argument("-c", "--chromedriver", required=True,
help="Chromedriver executable (download from https://sites.google.com/a/chromium.org/chromedriver/downloads).")
parser.add_argument("-g", "--grades", required=True,
help="Path to CSV file containing (student id, grade) pairs.")
args = parser.parse_args(sys.argv[1:])
# Read grades
grades = {}
with open(args.grades, 'r') as reader:
for line in reader:
sep = ',' if ',' in line else None
split = line.strip().split(sep)
if len(split) == 2:
student_id = split[0].strip()
grade = split[1].strip()
grades[student_id] = grade
print("Read grades of %d students." % len(grades))
# Open edoz homepage in selenium-accessible browser
driver = webdriver.Chrome(args.chromedriver)
driver.get(EDOZ_URL)
# Replace Python 2 input with raw_input
try:
input = raw_input
except NameError:
pass
print("Please login to edoz and navigate to the grades page.")
input("Then press enter to continue.")
# Fill in the grades
table = driver.find_element_by_xpath("//table[@class='tablelist']")
rows = driver.find_elements_by_tag_name('tr')
for row in rows:
cells = row.find_elements_by_tag_name('td')
if len(cells) > 8:
student_id = cells[2].text.strip()
if student_id in grades:
grade_field = cells[8].find_element_by_tag_name('input')
grade_field.send_keys(grades[student_id])
# If you want to delete all of the grades, uncomment the following:
# from selenium.webdriver.common.keys import Keys
# for _ in range(4):
# grade_field.send_keys(Keys.BACKSPACE)
# Press save
driver.find_element_by_name('buttons.save.name').click()