-
Notifications
You must be signed in to change notification settings - Fork 3
/
SiakTzu.py
128 lines (116 loc) · 4.4 KB
/
SiakTzu.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
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
import sys
import time
import datetime
options = Options()
driver = webdriver.Firefox(options=options)
login_url = "https://academic.ui.ac.id/main/Authentication/"
homepage_url = "https://academic.ui.ac.id/main/Welcome/"
logout_url = "https://academic.ui.ac.id/main/Authentication/Logout"
siak_url = "https://academic.ui.ac.id/main/CoursePlan/CoursePlanEdit"
# siak_url = "file:///C:/Users/ASUS/Desktop/SiakTzu/Web/Penambahan%20IRS%20-%20Dennis%20Al%20Baihaqi%20Walangadi%20(1906400141)%3b%20Kurikulum%2009.00.12.01-2016%20-%20SIAK%20NG.html"
down_string = "Universitas Indonesia"
matkul_code = {"696009-3": "Komas - A",
"695927-3": "IR",
"695972-4": "Komputasi Awan",
"695926-3": "Semweb"}
# fill your login credentials here
Username = "hocky.yudhiono"
Password = ""
refresh_rate = 1
display_name = "Hocky Yudhiono" # yang ditampilin di pojok kanan atas siak. ex: Galangkangin Gotera
def logout_page():
print("Logging out!")
driver.get(logout_url)
time.sleep(0.1)
def login_page():
#driver.get(login_url)
username = driver.find_element(By.ID, "u")
username.clear()
username.send_keys(Username)
time.sleep(0.1)
password = driver.find_element(By.ID, "p")
password.clear()
password.send_keys(Password)
time.sleep(0.1)
driver.find_element(By.XPATH, "//input[@value='Login']").click()
time.sleep(2)
def war_page():
# driver.get(siak_url)
time.sleep(5)
for kode, name in matkul_code.items():
# antisipasi salah masukkin kode
try:
radio_input = driver.find_element(By.XPATH, f"//input[@value='{kode}']")
if(not radio_input.is_selected()):
radio_input.click()
print(f"{name} dipilih! (kode: {kode})")
time.sleep(0.1)
else:
print(f"{name} sudah dipilih! (kode: {kode})")
except:
print(f"{name} tidak ada! (kode: {kode})")
time.sleep(10)
button = driver.find_element(By.XPATH, "//input[@value='Simpan IRS']")
button.click()
if __name__ == "__main__":
error = True
while(True):
try:
if(error):
error = False
driver.get(login_url)
refresh_rate = 10
if(datetime.datetime.now().minute >= 50): refresh_rate = 3
if(datetime.datetime.now().minute >= 55 or datetime.datetime.now().minute <= 5): refresh_rate = 0.5
time.sleep(refresh_rate)
print(datetime.datetime.now())
# print(driver.current_url)
# refresh manual bre
if(driver.current_url != "https://academic.ui.ac.id/main/Welcome/" and not "Magister Kriminologi" in driver.page_source):
print("Trying to login bro!")
driver.get(login_url)
continue
elif(driver.current_url != "https://academic.ui.ac.id/main/Welcome/"):
login_page()
time.sleep(refresh_rate)
print(datetime.datetime.now())
print("Sended login request bro!")
if(not display_name in driver.page_source):
print("Siak down bro!")
time.sleep(0.2)
driver.get(login_url)
continue
if("guest" in driver.page_source):
print("Role guest bro!")
time.sleep(0.2)
logout_page()
driver.get(login_url)
continue
print("BOI SAFELY LOGGED IN!")
# case di homepage
driver.get(siak_url)
# logout, belom bisa ngisi
if not "Basis Data" in driver.page_source:
print("BELUM BISA NGISI")
logout_page()
driver.get(login_url)
continue
war_page()
# kalau gagal, ulang lagi ngisinya
if (not display_name in driver.page_source):
print("ngulang isi bre")
driver.get(siak_url)
time.sleep(0.5)
continue
print("SUKSESS")
break # SUKSES!!!
except KeyboardInterrupt:
sys.exit()
# except:
# print("Error happened")
# time.sleep(0.5)
# error = True
# continue