-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheduhw
executable file
·83 lines (73 loc) · 2.37 KB
/
eduhw
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
#!/usr/bin/python3
# module imports
import sys
from config import Config
import dategen as dg
from colors import *
from datetime import datetime
from selenium import webdriver
import time
# initialize webdriver
if(Config.driver.lower() == "firefox"):
options = webdriver.FirefoxOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
options.add_argument('--headless')
driver = webdriver.Firefox(service_log_path=os.path.devnull, options = options)
elif(Config.driver.lower() == "chrome"):
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
options.add_argument('--headless')
driver = webdriver.Chrome(Config.chrome, options = options)
dates = dg.generate(Config.days)
homework = []
# log into edupage
driver.get(Config.provider+"/login/")
username = driver.find_element_by_name("username")
password = driver.find_element_by_name("password")
username.send_keys(Config.username)
password.send_keys(Config.password)
driver.find_element_by_xpath("//input[@type='submit']").click()
# parse retrieved homework
driver.get(Config.provider+"/exam/?")
time.sleep(1)
# select homework within date range
for date in dates:
hwl = driver.find_elements_by_xpath(
"//li[@data-date='"
+ date
+ "']/div[@class='hwItemInner']/div[@class='hwCnt']/div[@class='hwTitle']"
)
for hw in hwl:
homework.append((hw.text, date))
driver.quit()
# stdout homework
try:
mode = sys.argv[1]
except:
mode = 0
if(mode == "--minimal" or mode == "-m"):
for hw in homework:
print(hw[0] + " " + hw[1])
elif(mode == "--formatted" or mode == "-f"):
for hw in homework:
title, body = hw[0].split(":", 1)
snum = 0
text = ""
for char in body:
if(char == " "):
snum = snum + 1
if(char == "\n"):
char = ""
if((snum % Config.Format.newline) == 0 and char == " "):
char = "\n"
text = text + char
date = datetime.strptime(hw[1], "%Y-%m-%d").strftime(Config.Format.date[1])
print(
Config.Format.title + title + ", " + end + "due " + Config.Format.date[0] + date + end
+ "\n" + text + "\n"
)
else:
for hw in homework:
print(hw[0] + "\n" + hw[1] + "\n")