-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
107 lines (69 loc) · 2.3 KB
/
main.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
from selenium import webdriver
from datetime import datetime
from email.message import EmailMessage
import smtplib
import config
import time
import traceback
from win10toast import ToastNotifier
print('\nRunning beer grabber...\n')
try:
# driver = webdriver.Chrome()
# Delete below three lines and uncomment above driver line to show browser
op = webdriver.ChromeOptions()
op.add_argument('headless')
driver = webdriver.Chrome(
'D:\\Python\\Services\\chromedriver.exe',
options=op)
"""SEARCH FUNCTION SECTION"""
# This was created so multiple searches
# can be performed when running script
def search(*args):
body = ''
for arg in args:
driver.get("https://thetapandbottle.com/northstore")
print("\nAccessing website...\n")
time.sleep(5)
frame = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to.frame(frame)
driver.find_element_by_class_name('search-label').click()
driver.find_element_by_id("search").send_keys(arg)
print(f'\nSearching for requested brew... {arg.title()}\n')
time.sleep(8)
titles = driver.find_elements_by_css_selector('div.name.bold')
prices = driver.find_elements_by_css_selector('span.price')
print(f'\nLocated {len(titles)} items for {arg.title()}\n')
body += f"You searched for: {arg.title()}\n\n"
for t, p in zip(titles, prices):
body += f"\t{t.text} - ${p.text}\n\n"
return body
"""END SEARCH FUNCTION SECTION"""
"""EMAIL SECTION"""
timestamp = datetime.now()
now = timestamp.strftime("%m/%d/%Y")
EMAIL_ADDRESS = config.email
EMAIL_PASS = config.pw
msg = EmailMessage()
msg['Subject'] = f'Tap and Bottle selections for {now}'
msg['From'] = EMAIL_ADDRESS
msg['To'] = 'j.olson.digital@gmail.com'
# Add what items to search for here
msg.set_content(search('left hand', 'firestone walker'))
print('\nPutting email together...\n')
smtp = smtplib.SMTP_SSL('smtp.gmail.com', 465)
smtp.login(EMAIL_ADDRESS, EMAIL_PASS)
smtp.send_message(msg)
"""END EMAIL SECTION"""
print('\nEmail sent!\n')
print('\nClosing!\n')
# Closes python box after program finishes
driver.quit()
except Exception:
toaster = ToastNotifier()
text = "ChromeDriver"
if text in traceback.format_exc():
print(toaster.show_toast(
"LHB Grabber",
"Program error:"
" ChromeDriver possibly requires update.",
duration=10))