-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathlegacy_rescheduler.py
82 lines (71 loc) · 2.79 KB
/
legacy_rescheduler.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
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from settings import TEST_MODE
# This is frankly very, very bad and should be rewritten with requests
# when I get a test account
def legacy_reschedule(driver):
driver.refresh()
date_selection_box = WebDriverWait(driver, 5).until(
EC.presence_of_element_located(
(
By.XPATH,
"/html/body/div[4]/main/div[4]/div/div/form/fieldset/ol/fieldset/div/div[2]/div[3]/li[1]/input",
)
)
)
date_selection_box.click()
# Move to next month
def next_month():
driver.find_element(By.XPATH, "/html/body/div[5]/div[2]/div/a").click()
# Check if avalible in current month
def cur_month_ava():
month = driver.find_element(By.XPATH, "/html/body/div[5]/div[1]/table/tbody")
dates = month.find_elements(By.TAG_NAME, "td")
for date in dates:
if date.get_attribute("class") == " undefined":
ava_date_btn = date.find_element(By.TAG_NAME, "a")
return True
return False
# Check the nearest slot is avalible in # months (0 for this month, 1 for next month...) and move to the month
def nearest_ava():
ava_in = 0
cur = cur_month_ava()
while not cur:
next_month()
cur = cur_month_ava()
ava_in += 1
return ava_in
avalible_in_months = nearest_ava()
# Reschedule if the avalible_in_months is less than or equal to wait month
print("Trying to pick time and reschedule...")
month = driver.find_element(By.XPATH, "/html/body/div[5]/div[1]/table/tbody")
dates = month.find_elements(By.TAG_NAME, "td")
ava_date_btn = None
for date in dates:
if date.get_attribute("class") == " undefined":
ava_date_btn = date.find_element(By.TAG_NAME, "a")
break
ava_date_btn.click()
# Select time of the date:
sleep(2)
appointment_time = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "appointments_consulate_appointment_time"))
)
appointment_time.click()
appointment_time_options = appointment_time.find_elements(By.TAG_NAME, "option")
appointment_time_options[len(appointment_time_options) - 1].click()
# Click "Reschedule"
driver.find_element(
By.XPATH,
"/html/body/div[4]/main/div[4]/div/div/form/div[2]/fieldset/ol/li/input",
).click()
try:
confirm = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "/html/body/div[6]/div/div/a[2]"))
)
finally:
driver.implicitly_wait(0.1)
if not TEST_MODE:
confirm.click()