-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblazefunction.py
More file actions
81 lines (62 loc) · 2.96 KB
/
blazefunction.py
File metadata and controls
81 lines (62 loc) · 2.96 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import time
def blaze_pizza_survey(email):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument("--ignore-certificate-errors")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
#chrome_options.add_argument("--incognito")
chrome_options.binary_location = '/opt/render/project/.render/chrome/opt/google/chrome' #for render.com
driver = webdriver.Chrome(options=chrome_options)
def wait_for_new_url(driver, previous_url, timeout=5):
def url_changed(driver):
return driver.current_url != previous_url
wait = WebDriverWait(driver, timeout)
wait.until(url_changed)
try:
driver.get("https://www.tellblazepizza.com/")
current_url = driver.current_url
wait = WebDriverWait(driver, 3)
while not driver.current_url.startswith("https://www.tellblazepizza.com/Survey.aspx"):
next_button = driver.find_element(by="id", value="NextButton")
next_button.click()
wait_for_new_url(driver, current_url)
search_text = "Please provide your email address below to receive your offer. This information will not be used for any other purpose."
page_source = driver.page_source
while search_text not in page_source:
wait.until(EC.visibility_of_element_located((By.ID, "NextButton")))
next_button = driver.find_element(by="id", value="NextButton")
next_button.click()
wait_for_new_url(driver, current_url)
page_source = driver.page_source
send_email = driver.find_element(by="id", value="S000031")
send_email.send_keys(email)
conf_email = driver.find_element(by="id", value="S000032")
conf_email.send_keys(email)
wait.until(EC.visibility_of_element_located((By.ID, "NextButton")))
next_button = driver.find_element(by="id", value="NextButton")
next_button.click()
if driver.current_url.startswith("https://www.tellblazepizza.com/Finish.aspx"):
result = "Success! Coupon sent to your email. - Blaze Pizza (works online)"
else:
result = "Unexpected page encountered."
except Exception as e:
result = f"An error occurred: {str(e)}"
finally:
driver.quit()
return result
def main():
email = input("Enter your email: ")
result = blaze_pizza_survey(email)
print(result)
if __name__ == "__main__":
main()