-
Notifications
You must be signed in to change notification settings - Fork 10
/
Favourite food notifier WIN.py
38 lines (32 loc) · 1.39 KB
/
Favourite food notifier WIN.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
#! python3
import bs4, requests, smtplib
# ------------------- E-mail list ------------------------
toAddress = ['[email protected]','[email protected]']
# --------------------------------------------------------
#Download page
getPage = requests.get('http://www.somesite.com/menu')
getPage.raise_for_status() #if error it will stop the program
#Parse text for foods
menu = bs4.BeautifulSoup(getPage.text, 'html.parser')
foods = menu.select('.foodname')
the_one = 'borzaska' # This is the name of the food you are looking for
flength = len(the_one)
available = False
for food in foods:
for i in range(len(food.text)):
chunk = food.text[i:i+flength].lower()
if chunk == the_one:
available = True
if available == True:
conn = smtplib.SMTP('smtp.gmail.com', 587) # smtp address and port
conn.ehlo() # call this to start the connection
conn.starttls() # starts tls encryption. When we send our password it will be encrypted.
conn.login('[email protected], 'appkey')
conn.sendmail('[email protected]', toAddress, 'Subject: Borzaska Alert!\n\nAttention!\n\nYour favourite food is available today!\n\nBon apetite!:\nFood Notifier V1.0')
conn.quit()
print('Sent notificaton e-mails for the following recipients:\n')
for i in range(len(toAddress)):
print(toAddress[i])
print('')
else:
print('Your favourite food is not available today.')