forked from CSN7841/UKSpainVisa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.py
65 lines (54 loc) · 1.89 KB
/
monitor.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
import ssl
import time
from utils.config import TIMEOUT
from utils.config import USERS
from utils.log import logger
from visa import Visa
import undetected_chromedriver as uc
import threadpool
import pyttsx3
def init_driver():
profile = {
"profile.default_content_setting_values.notifications": 1 # block notifications
}
ssl._create_default_https_context = ssl._create_unverified_context
chrome_options = uc.ChromeOptions()
chrome_options.add_experimental_option('prefs', profile)
chrome_options.add_argument("--incognito")
driver = uc.Chrome(chrome_options=chrome_options)
driver.implicitly_wait(10)
driver.delete_all_cookies()
return driver
def monitor(email, password, url, centers, mode):
driver = init_driver()
visa = Visa(driver)
try:
time.sleep(1)
visa.go_to_appointment_page(url)
time.sleep(1)
visa.login(email, password)
time.sleep(1)
visa.go_to_book_appointment(url, email)
visa.select_centre(centers[0], centers[1], centers[2], email)
while True:
dates = visa.check_available_dates(mode, centers[3], email)
if dates:
logger.info(f"USER {email} DAY AVAILABLE: {dates}")
pyttsx3.speak(f"say day available {email} {dates}")
time.sleep(10)
# 10s 后继续进入下一个循环
else:
logger.info(f"{email}: NO DAY AVAILABLE...")
driver.refresh()
time.sleep(TIMEOUT)
except Exception as e:
logger.error(f'Monitor runtime error from {email} {e}')
driver.quit()
monitor(email, password, url, centers, mode)
if __name__ == "__main__":
# 执行部分
pool = threadpool.ThreadPool(len(USERS))
gl_tasks = threadpool.makeRequests(monitor, USERS)
for task in gl_tasks:
pool.putRequest(task)
pool.wait()