-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathprice_email.py
34 lines (28 loc) · 949 Bytes
/
price_email.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
import requests
from bs4 import BeautifulSoup
import smtplib
URL = "" # add the link
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/87.0.4280.141 Safari/537.36 OPR/73.0.3856.396"} # add custom headers
def send_email():
sever=smtplib.SMTP('smtp.gmail.com',587)
sever.ehlo()
sever.starttls()
sever.ehlo()
sever.login('','') # Add credentials in the format is {user},{password}
body=URL
msg=f"Body:{body}\nThe price has dropped"
sever.sendmail("","",msg)
sever.quit()
def check_price():
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
price = soup.find(id='priceblock_ourprice').getText()
price=price.replace(",","")
price=price.split('.',1)
sub_price=price[0]
sub_price=int(sub_price)
print(sub_price)
if sub_price < 2999:
send_email()
check_price()