-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisaappointmentbot.py
69 lines (60 loc) · 2.94 KB
/
visaappointmentbot.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
import csv
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
import dateutil.parser as dparser
import datetime
import os
import re
def login():
driver = webdriver.Chrome(r'C:\Users\lpenatre\Downloads\chromedriver.exe')
driver.get("https://pastel.diplomatie.gouv.fr/rdvinternet/html-4.02.00/frameset/frameset.html?lcid=1&sgid=193&suid=2")
driver.switch_to.frame(WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "BODY_WIN"))))
sleep(5)
driver.execute_script("parent.parent.ComposantMenuFrameset.SelectItem2Menu1(0,0,false)")
driver.switch_to.frame(WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "CONTENU_WIN"))))
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "ccg"))).click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "boutonSuivant"))).click()
#driver.execute_script("tabElementForm[0].suivant()")
return driver
#login = driver.find_element_by_class_name("menu1Item2")
#login.click()
#driver.find_element_by_id("boutonSuivant_link")
#driver.click()
#sleep(5)
#driver.close()
def is_valid_appt(driver):
print(driver.find_element_by_id("compTableau_Entete").text)
d = dparser.parse(re.sub("[^0-9/]+", "", driver.find_element_by_id("compTableau_Entete").text))
d = d.date()
print(d)
return datetime.date.today() <= d <= datetime.date(2021, 8, 18)
def check_for_appts():
try:
driver = login()
while True:
try:
WebDriverWait(driver, 3).until(EC.alert_is_present(),
'Timed out waiting for PA creation ' +
'confirmation popup to appear.')
alert = driver.switch_to_alert()
alert.accept()
print("alert accepted")
except TimeoutException:
if is_valid_appt(driver):
os.system('say "an appointment has been found hella sick"')
input("Press ENTER to continue.")
sleep(30)
driver.refresh()
driver.switch_to.frame(WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "BODY_WIN"))))
driver.switch_to.frame(WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "CONTENU_WIN"))))
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "boutonSuivant"))).click()
except TimeoutException:
driver.quit()
check_for_appts()
check_for_appts()