-
Notifications
You must be signed in to change notification settings - Fork 1
/
koreksi.py
74 lines (64 loc) · 2.15 KB
/
koreksi.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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
import random
my_long_query = """
let linkLocationQuery = "ol li a[href]:first-child"
if (document.querySelectorAll(linkLocationQuery).length === 0) {
linkLocationQuery = "h3 a[href]:first-child"
}
if (document.querySelectorAll(linkLocationQuery).length === 0) {
linkLocationQuery = "a[href]"
}
function cekLink() {
let counter = 1;
document.querySelectorAll(linkLocationQuery).forEach(x => {
console.log(`${counter++}.) ${x.href}`);
})
}
function mulaiCek() {
let counter = 1;
document.querySelectorAll(linkLocationQuery).forEach(x => {
let number = counter++;
fetch(`https://cors-anywhere.herokuapp.com/${x.href}`).then(resp => {
if (resp.status === 200) console.log(`${number} OK`);
else console.log(`${number} FAIL`);
})
})
}
console.log("Listing Link...");
cekLink();
console.log("Checking Link");
mulaiCek();
"""
def request_cors_access(selenium):
print("Requesting CORS access...")
selenium.get("https://cors-anywhere.herokuapp.com/corsdemo")
request_btn = selenium.find_element_by_css_selector('input[type=submit]')
request_btn.send_keys(Keys.RETURN)
time.sleep(1)
def mulai_koreksi_github_os(selenium):
# Change this as needed
os_repo = 'os211'
os_week = 'W03'
with open('asdosan.txt', 'r') as reader:
asdosan = reader.readline()
while asdosan != '':
asdosan = asdosan.strip()
print(f"Checking {asdosan}'s repository...")
topten_url = f'https://{asdosan}.github.io/{os_repo}/{os_week}'
selenium.get(topten_url)
time.sleep(1)
selenium.execute_script(my_long_query)
time.sleep(1)
input("Ready to continue? ")
asdosan = reader.readline()
def main():
chrome_options = Options()
# chrome_options.add_argument('--headless')
selenium = webdriver.Chrome(options = chrome_options)
request_cors_access(selenium)
mulai_koreksi_github_os(selenium)
if __name__ == '__main__':
main()