-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckClass.py
More file actions
59 lines (50 loc) · 1.75 KB
/
CheckClass.py
File metadata and controls
59 lines (50 loc) · 1.75 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
from selenium.webdriver.common.keys import Keys
import time
from termcolor import colored
from settings import driver
from Classes.login import join_again
def add(hour, val):
return str(int(hour) + val)
#get current time
def ryt_now():
cur_time = time.localtime()
cur_time=time.strftime("%H:%M:%S",cur_time)
return cur_time
#get hour form ryt_now()
def get_time():
cur_time = ryt_now()
hour, mn, sec = cur_time.split(':')
if int(mn) >= 40:
hour = str((int(hour) + 1))
return hour
def process_hr(cur_hr, minutes):
if int(cur_hr) > 12:
cur_hr = str((int(cur_hr) - 12))
cur = str((minutes + 60) % 60)
if len(cur) < 2:
cur = '0' + cur
return cur_hr + ':' + cur
# check for classes from cur time t in order t - 1, t, t + 1
# handle false positive of night
# can be more efficient
def check_for_class(hour):
print(colored('Checking for ongoing class', 'cyan'))
for cur_hr in [add(hour, -2), add(hour, -1), hour, add(hour, 1)]:
for minutes in range(0, 60):
val = process_hr(cur_hr, minutes)
# print('Checking class at', val)
try:
path = "//div[@data-start='" + val + "']"
current_class = driver.find_element_by_xpath(path)
extra_check = current_class.get_attribute('data-full')
if len(extra_check) > 8:
continue
print(val, ' - Class Found')
# elements = driver.find_elements_by_class_name('fc-title')
# for e in elements:
# print(e.text)
current_class.find_element_by_xpath("./../..").send_keys(Keys.RETURN)
return val
except:
pass
return False