-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_rank.py
More file actions
62 lines (53 loc) · 2.34 KB
/
get_rank.py
File metadata and controls
62 lines (53 loc) · 2.34 KB
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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
from selenium.common.exceptions import NoSuchElementException, InvalidSessionIdException
import time
import sys
import os
import re
def get_rank(team_name="22222222222222222222222222222222"):
print("Calling get_rank()...")
# sets up selenium driver with correct Chrome headless version
os.environ['WDM_LOG_LEVEL'] = '0' # suppress logs from ChromeDriverManager install
options = webdriver.ChromeOptions()
options.headless = True
driver = webdriver.Chrome(ChromeDriverManager(version="96.0.4664.45").install(), options=options)
url = "https://berkeley-cs170.github.io/project-leaderboard-fa21/?team={}".format(team_name)
driver.get(url)
# time.sleep(8)
i = 1
rank_dict = {}
while True:
try:
name_selector = "//*[@id=\"table\"]/table/tr[{}]/td[1]/span/a".format(i)
name = driver.find_element_by_xpath(name_selector).text
rank_selector = "//*[@id=\"table\"]/table/tr[{}]/td[2]".format(i)
rank = driver.find_element_by_xpath(rank_selector).text
rank_dict[name] = int(rank)
i += 1
if i % 100 == 0:
print("progress: {} / 899".format(i))
except NoSuchElementException:
if i == 1:
pass
else:
break
not_first = [item[0] for item in rank_dict.items() if item[1] != 1]
more_than_ten = [item[0] for item in rank_dict.items() if item[1] > 10]
more_than_twenty = [item[0] for item in rank_dict.items() if item[1] > 20]
try:
driver.close()
except InvalidSessionIdException:
pass
return rank_dict, not_first, more_than_ten, more_than_twenty
if __name__ == '__main__':
rank_dict, not_first, more_than_ten, more_than_twenty = get_rank()
print("\n=========================================================\n")
print("rank dict:\n", rank_dict)
print("\n=========================================================\n")
print("not first:\n", not_first)
print("\n=========================================================\n")
print("more than 10:\n", more_than_ten)
print("\n=========================================================\n")
print("more than 20:\n", more_than_twenty)