Merge pull request #278 from ighoshsubho/master

Added python file for tracking product prices in Amazon
This commit is contained in:
Bartick Maiti 2022-10-10 22:04:21 +05:30 committed by GitHub
commit b6abf9577d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,11 @@
# Amazon Price Tracker
A price tracker app in python that will keep track your product price and will mail you when the price wents down.
## Usage/Examples
* 3 packages required requests, beautifulsoup, smtplib
* Use pip install requests, pip install bs4 and pip install secure-smtplib
* run scap.py file

View File

@ -0,0 +1,50 @@
import time
import requests # Will help us to get out url directed
from bs4 import BeautifulSoup # Will help us to scrap us the data
import os
import smtplib # this module is used for sending mail
from email.message import EmailMessage
email_id = os.environ.get("EMAIL_ADDR")
email_pass = os.environ.get("EMAIL_PASS")
# I have used this since I have hidden my credentials
URL = "https://www.amazon.in/Apple-MacBook-Chip-13-inch-256GB/dp/B08N5W4NNB/ref=sr_1_3?crid=3BF9J6OT56GW0&keywords=macbook+m1&qid=1665331351&qu=eyJxc2MiOiIzLjgzIiwicXNhIjoiMi43NiIsInFzcCI6IjEuNTIifQ%3D%3D&sprefix=macbook+m1%2Caps%2C3675&sr=8-3"
def check_price():
#Copy url of the product that you are looking for
headers = {"user-Agents" : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'}
# Now lets print our product title to veerify that its working
page = requests.get(URL, headers = headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(class_ = "a-size-large product-title-word-break").get_text()
price = soup.find(class_ = "a-price-whole").get_text()
converted_price = price[:6].replace(",","") # We don't want comma so we replaced with ""
print(title.strip())
print(converted_price)
# Now we will send mail if the converted price is less than present price
if(converted_price < 92890):
send_mail()
def send_mail():
message = EmailMessage()
message['Subject'] = "Your favourite product is now at cheaper price!!😍"
message['From'] = email_id
message['to'] = "mobir99513@lutota.com" #Any random email you can give whom you want to send the email
message.set_content("Hey check this amazon link : https://www.amazon.in/Apple-MacBook-Chip-13-inch-256GB/dp/B08N5W4NNB/ref=sr_1_3?crid=3BF9J6OT56GW0&keywords=macbook+m1&qid=1665331351&qu=eyJxc2MiOiIzLjgzIiwicXNhIjoiMi43NiIsInFzcCI6IjEuNTIifQ%3D%3D&sprefix=macbook+m1%2Caps%2C3675&sr=8-3")
with smtplib.SMTP_SSL('smtp.gmail.com',465) as smtp: #465 is the port number
smtp.login(email_id, email_pass)
smtp.send_message(message)
while True:
check_price()
time.sleep(10)