-
Notifications
You must be signed in to change notification settings - Fork 0
/
LectureBot.py
79 lines (65 loc) · 2.15 KB
/
LectureBot.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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import sys
import time
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
# command = sys.argv[1]
username = sys.argv[1]
password = sys.argv[2]
course = sys.argv[3]
driver.get("https://moodle.iitd.ac.in/login/index.php")
loginId = driver.find_element_by_id("username")
loginId.send_keys(username)
pwd = driver.find_element_by_id("password")
pwd.send_keys(password)
captcha = driver.find_element_by_id("login")
st = captcha.text
ls = st.split(" ")
flag = 1
for i in range(len(ls)):
if ls[i] == '+':
res = int(ls[i-1]) + int(ls[i+1])
break
elif ls[i] == '-':
res = int(ls[i-1]) - int(ls[i+1])
break
elif ls[i] == 'second':
flag = 2
elif ls[i] == ',':
if flag == 1:
res = int(ls[i-1])
else:
res = int(ls[i+1])
break
captchaAnswer = driver.find_element_by_id("valuepkg3")
captchaAnswer.clear()
captchaAnswer.send_keys(str(res))
submit_button = driver.find_element_by_id("loginbtn")
submit_button.click()
# if command == 'login':
# username = sys.argv[2]
# password = sys.argv[3]
# login(username, password)
siteHomeClass = driver.find_element_by_id("inst4")
listOfa = siteHomeClass.find_elements_by_tag_name("a")
siteHome = listOfa[1]
linkSiteHome = siteHome.get_attribute("href")
driver.get(linkSiteHome)
maindiv = driver.find_element_by_id("frontpage-course-list")
courseClass1hd = maindiv.find_elements_by_tag_name("h3")
for i in range(len(courseClass1hd)):
courseClass1a = courseClass1hd[i].find_element_by_tag_name("a")
courseClass1Name = courseClass1a.text
if course in courseClass1Name:
link = courseClass1a.get_attribute("href")
driver.get(link)
break
impartusClass = driver.find_elements_by_class_name("activityinstance")
impartusClassA = impartusClass[1].find_element_by_tag_name("a")
link = impartusClassA.get_attribute("href")
driver.get(link)
#boom we r at the lectures page