-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
154 lines (114 loc) · 5.01 KB
/
script.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# modules required
import os
import winsound
import requests
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
# telegram credentials (please refer to telegram documentation: https://core.telegram.org/bots/features#creating-a-new-bot)
telegram_enabled = True
telegram_token = "0"
telegram_chatid = "0"
# check if telegram credentials are provided
if (telegram_token == "0") or (telegram_chatid == "0"):
telegram_enabled = False
print("- Telegram credentials not provided. Messages will only be printed in the prompt.")
else:
print("Telegram configuration: Success!")
# check if firefox web driver is placed in the project folder
if not os.path.isfile("geckodriver.exe"):
print("- Firefox web driver not found in project folder.")
print("Quitting...")
quit()
else:
print("Firefox web driver configuration: Success!")
# access website
driver = webdriver.Firefox()
vfs_website = driver.get("https://visa.vfsglobal.com/rus/ru/nld/login")
print("Opening VFS website...")
while True:
input("Log in manually and click 'Записаться на прием' in the following page.\nThen come back here and type ENTER: ")
break
sleep(1)
print("Bot has started. See updates below.")
# initial fill of field 'Выберите свой визовый центр'
driver.find_element(By.ID, "mat-select-value-1").click()
sleep(1)
ActionChains(driver).send_keys(Keys.ARROW_DOWN).perform()
sleep(1)
ActionChains(driver).send_keys(Keys.ARROW_DOWN).perform()
sleep(1)
ActionChains(driver).send_keys(Keys.ARROW_DOWN).perform()
sleep(1)
ActionChains(driver).send_keys(Keys.ENTER).perform()
sleep(10)
# initial fill of field 'Выберите категорию записи'
driver.find_element(By.ID, "mat-select-value-5").click()
sleep(1)
ActionChains(driver).send_keys(Keys.ENTER).perform()
sleep(10)
# initial fill of field 'Выберите подкатегорию'
driver.find_element(By.ID, "mat-select-value-3").click()
sleep(1)
ActionChains(driver).send_keys(Keys.ARROW_DOWN).perform()
sleep(1)
ActionChains(driver).send_keys(Keys.ENTER).perform()
sleep(10)
def no_updates_msg():
if telegram_enabled:
url = f"https://api.telegram.org/bot{telegram_token}/sendMessage"
post_data = {"chat_id": telegram_chatid, "parse_mode": "Markdown", "text": "No available slots. Keep trying."}
requests.post(url, data=post_data)
def good_news_msg():
if telegram_enabled:
url = f"https://api.telegram.org/bot{telegram_token}/sendMessage"
post_data = {"chat_id": telegram_chatid, "parse_mode": "Markdown", "text": "There may be slots available. Try to make an appointment now."}
requests.post(url, data=post_data)
while True:
# try to spot error message
try:
error_msg = driver.find_element(By.XPATH, "/html/body/app-root/div/div/app-eligibility-criteria/section/form/mat-card[1]/form/div[4]/div")
if "Приносим извинения" in error_msg.text: # means there are no slots available
print("No available slots. Keep trying.")
#no_updates_msg()
# change selection in field 'Выберите свой визовый центр'
driver.find_element(By.ID, "mat-select-value-1").click()
sleep(1)
ActionChains(driver).send_keys(Keys.ARROW_DOWN).perform()
sleep(1)
ActionChains(driver).send_keys(Keys.ENTER).perform()
sleep(10)
driver.find_element(By.ID, "mat-select-value-1").click()
sleep(1)
ActionChains(driver).send_keys(Keys.ARROW_UP).perform()
sleep(1)
ActionChains(driver).send_keys(Keys.ENTER).perform()
sleep(10)
# change selection in field 'Выберите категорию записи'
driver.find_element(By.ID, "mat-select-value-5").click()
sleep(1)
ActionChains(driver).send_keys(Keys.ENTER).perform()
sleep(10)
# change selection in field 'Выберите подкатегорию'
driver.find_element(By.ID, "mat-select-value-3").click()
sleep(1)
ActionChains(driver).send_keys(Keys.ARROW_DOWN).perform()
sleep(1)
ActionChains(driver).send_keys(Keys.ENTER).perform()
sleep(10)
continue
else: # means there may be slots available
winsound.Beep(440, 1000)
print("There may be slots available. Try to make an appointment now.")
good_news_msg()
break
except KeyboardInterrupt:
print("Script interrupted.")
break
except: # means there may be slots available
winsound.Beep(440, 1000)
print("There may be slots available. Try to make an appointment now.")
good_news_msg()
break