├── README.md └── price-tracker.py /README.md: -------------------------------------------------------------------------------- 1 | # amazon-price-tracker-python 2 | This is a simple price tracker app using python that regularly compares the prices of your favorite stuff on amazon and sends you a customized notification email to tell you if the prices fell down. 3 | This uses python and implements beautiful soup, smtplib, time and requests modules and libraries. 4 | The libraries, modules and other tools referred during this task are as follows: 5 |

Send mail from your Gmail account using Python

6 | 11 | 12 |

Price Tracker using Python

13 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /price-tracker.py: -------------------------------------------------------------------------------- 1 | # import required files and modules 2 | 3 | import requests 4 | from bs4 import BeautifulSoup 5 | import smtplib 6 | import time 7 | 8 | # set the headers and user string 9 | headers = { 10 | "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" 11 | } 12 | 13 | # send a request to fetch HTML of the page 14 | response = requests.get('https://www.amazon.in/Bose-SoundLink-Wireless-Around-Ear-Headphones/dp/B0117RGG8E/ref=sr_1_11?qid=1562395272&refinements=p_89%3ABose&s=electronics&sr=1-11', headers=headers) 15 | 16 | # create the soup object 17 | soup = BeautifulSoup(response.content, 'html.parser') 18 | 19 | # change the encoding to utf-8 20 | soup.encode('utf-8') 21 | 22 | #print(soup.prettify()) 23 | 24 | # function to check if the price has dropped below 20,000 25 | def check_price(): 26 | title = soup.find(id= "productTitle").get_text() 27 | price = soup.find(id = "priceblock_ourprice").get_text().replace(',', '').replace('₹', '').replace(' ', '').strip() 28 | #print(price) 29 | 30 | #converting the string amount to float 31 | converted_price = float(price[0:5]) 32 | print(converted_price) 33 | if(converted_price < 20000): 34 | send_mail() 35 | 36 | #using strip to remove extra spaces in the title 37 | print(title.strip()) 38 | 39 | 40 | 41 | 42 | # function that sends an email if the prices fell down 43 | def send_mail(): 44 | server = smtplib.SMTP('smtp.gmail.com', 587) 45 | server.ehlo() 46 | server.starttls() 47 | server.ehlo() 48 | 49 | server.login('email@gmail.com', 'password') 50 | 51 | subject = 'Price Fell Down' 52 | body = "Check the amazon link https://www.amazon.in/Bose-SoundLink-Wireless-Around-Ear-Headphones/dp/B0117RGG8E/ref=sr_1_11?qid=1562395272&refinements=p_89%3ABose&s=electronics&sr=1-11 " 53 | 54 | msg = f"Subject: {subject}\n\n{body}" 55 | 56 | server.sendmail( 57 | 'sender@gmail.com', 58 | 'receiver@gmail.com', 59 | msg 60 | ) 61 | #print a message to check if the email has been sent 62 | print('Hey Email has been sent') 63 | # quit the server 64 | server.quit() 65 | 66 | #loop that allows the program to regularly check for prices 67 | while(True): 68 | check_price() 69 | time.sleep(60 * 60) --------------------------------------------------------------------------------