-
Notifications
You must be signed in to change notification settings - Fork 0
/
siak-what.py
139 lines (122 loc) · 4.68 KB
/
siak-what.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
127
128
129
130
131
132
133
134
135
136
137
138
139
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
def war(username, password, display_name):
options = webdriver.FirefoxOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
driver = webdriver.Firefox(options=options)
driver.set_page_load_timeout(5)
print(f"Username: {username}")
print(f"Password: {password}")
login(driver, username, password, display_name)
while True:
try:
driver.get("https://academic.ui.ac.id/main/CoursePlan/CoursePlanEdit")
element = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CLASS_NAME, "rinfo")))
# Keep this up to date
# ganti dengan matkul yang namanya pasti ada
if ("Analisis Numerik" in driver.page_source):
break
raise NoSuchElementException
except:
print("Retrying... (Belum mulai)")
logout(driver)
login(driver, username, password, display_name)
continue
matkul=[]
with open('matkul.txt') as file_inp:
for line in file_inp:
matkul.append(line.strip())
print("Matkul Loaded")
try:
for kelas in matkul:
try:
radio_input = driver.find_element_by_xpath('//input[@value="{}"]'.format(kelas))
if(not radio_input.is_selected()):
radio_input.click()
print(f"{kelas} chosen!)")
time.sleep(0.1)
else:
print(f"{kelas} SUDAH DIPILIH!)")
time.sleep(30)
except:
raise NoSuchElementException
break
except NoSuchElementException:
print("input tidak valid")
print("EXITING...")
else:
driver.find_element_by_name('submit').click()
while True:
if ("IRS berhasil tersimpan!" in driver.page_source or "Daftar IRS" in driver.page_source):
print("Process finished! Press enter to exit...")
break
else:
print("Mencoba simpan IRS...")
driver.refresh()
input()
driver.close()
def login(driver, username, password, display_name):
print("Logging in...")
while True:
try:
driver.get("https://academic.ui.ac.id/main/Authentication/")
element = driver.find_element_by_id("u")
element.send_keys(username)
element = driver.find_element_by_name("p")
element.send_keys(password)
element.send_keys(Keys.RETURN)
element = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CLASS_NAME, "rinfo")))
except:
try:
driver.get("https://academic.ui.ac.id/main/Welcome/")
if (("Logout Counter" in driver.page_source or display_name in driver.page_source) and "S1 Reguler Ilmu Komputer" in driver.page_source):
print("Logged in!")
break
else:
print("Role Error")
logout(driver)
except:
continue
try:
if (("Logout Counter" in driver.page_source or display_name in driver.page_source) and "S1 Reguler Ilmu Komputer" in driver.page_source):
print("Logged in!")
break
else:
print("Role Error")
logout(driver)
raise Exception
except:
continue
def logout(driver):
print("Logging out...")
while True:
try:
driver.get("https://academic.ui.ac.id/main/Authentication/Logout")
element = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, "u")))
except:
try:
driver.get("https://academic.ui.ac.id/main/Welcome/")
driver.find_element_by_id("u")
print("Logged out!")
break
except:
continue
try:
driver.find_element_by_id("u")
print("Logged out!")
break
except:
continue
if __name__ == "__main__":
print("Starting...")
uspass=[]
with open('credentials.txt') as file_inp:
for line in file_inp:
uspass.append(line.strip())
war(uspass[0],uspass[1], uspass[2])