-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAmazon_Price_Check.py
63 lines (41 loc) · 1.4 KB
/
Amazon_Price_Check.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
import requests
from bs4 import BeautifulSoup
import smtplib
import time
# URL Of the product on amazon, Only amazon is supported
URL = 'PRODUCT_URL'
# Change the User-Agent to your computer's
headers = {"User-Agent": 'YOUR_USER-AGENT}
# User Defined variables
# To Authenticate Email access you may have to enable 2-Factor Authenctivcation on your Gmail account
# Then Generate Google App Password for the Mail app, And Use the Password here.
Email = 'YOUR_EMAIL_ADDRESS'
password = 'YOUR_PASSWORD'
ToEmail = 'TO_EMAIL_ADDRESS'
Checking_Interval = 60 # In Seconds
# Email Subject & Body
Subject = 'YOUR_MESSAGE_SUBJECT'
Body = 'YOUR_MESSAGE_BODY'
def check_Price():
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(id="productTitle").get_text()
price = soup.find(id="priceblock_ourprice").get_text()
converted_Price = float(price[2:7].replace(',', ''))
if(converted_Price < 2000.00):
send_mail()
print(converted_Price)
print(title.strip())
def send_mail():
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(Email, password)
msg = 'Subject: %s\n\n%s'%(Subject, Body)
server.sendmail(Email, ToEmail, msg)
print('HEY MAIL HAS BEEN SENT')
server.quit()
while(True):
check_Price()
time.sleep(Checking_Interval)