diff --git a/Amazon_Price_Tracker.py b/Amazon_Price_Tracker.py new file mode 100644 index 0000000..60cb62a --- /dev/null +++ b/Amazon_Price_Tracker.py @@ -0,0 +1,90 @@ +#Importing modules +import requests +from bs4 import BeautifulSoup +from pushbullet import PushBullet +from threading import Timer + +URL = 'https://www.amazon.in/New-Apple-iPhone-Pro-128GB/dp/B08L5VZKWT/ref=sr_1_3?dchild=1&keywords=iphone&qid=1616338851&sr=8-3' + #URL of the product page(On Amazon) +desired_price=130000 #Price below which you should be notified +API_KEY = '' #Access Token from pushbullet +interval=1 #Enter value in hours(If interval=2 the program checks the price every 2 hours) + + +headers = { +'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36', +'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', +'Accept-Language' : 'en-US,en;q=0.5', +'Accept-Encoding' : 'gzip', +'DNT' : '1', # Do Not Track Request Header +'Connection' : 'close' +} + #Web Scraping + + + +def notification(product_name,product_price): #Function which is used to send notification on our phone + + text=product_name + text+=' is now available for your desired price.' + text+='\n You can get it now at ' + text+=product_price + text+='\n' + text+=URL #Text contains the message which will be displayed as notification + + pb=PushBullet(API_KEY) #Class Variable of API_KEY + + push = pb.push_note('Price Drop',text) #Sending Notification + #Title of Notification followed by text inside the parenthesis + + print('Notification Sent!') #Prints 'Notification Sent' on your terminal + + +def check_price(): + page = requests.get(URL,headers=headers) + soup = BeautifulSoup(page.content,'html.parser') + + product_name = soup.find(id='productTitle').get_text() #Finds id called productTitle which contains + #the name of the product on Amazon Page + product_name = str(product_name) #Converts it into text + product_name = product_name.strip() #It has a lot of extra spaces so removing them + #print(product_name) + + +#In some pages price of the product is stored in id='priceblock_ourprice' and in some it is stored in id='priceblock_dealprice' +#and some in id='priceblock_saleprice' + +#There may be cases that we have ignored, We will work on it and correct the code later on + a=soup.find(id='priceblock_ourprice') + if(a!=None): + product_price1 = soup.find(id='priceblock_ourprice').get_text() + else: + a=soup.find(id='priceblock_dealprice') + if(a!=None): + product_price1 = soup.find(id='priceblock_dealprice').get_text() + else: + product_price1 = soup.find(id='priceblock_saleprice').get_text() + #print(product_price1) + + product_price ='' + for letters in product_price1: + if letters.isnumeric() or letters =='.': + product_price+=letters + product_price=float(product_price) + #Price contains the rupee symbol so removing that and making it a float + + #print(product_price) + + if product_price<=desired_price: + print("Price of the Product reached below the Desired Price.") + notification(product_name,product_price1) + return + else: + print("Price of the Product is still more than the Desired Price.") + #This blocks compares the price and calls the notification function if necessary + + Timer(interval*60*60,check_price).start() + #This statement controls the time after which loop is run again + #That is the time gap after which we should check the price + +check_price() diff --git a/PROJECT REPORT.pdf b/PROJECT REPORT.pdf new file mode 100644 index 0000000..cfbd791 Binary files /dev/null and b/PROJECT REPORT.pdf differ diff --git a/README.md b/README.md index a469fa4..94b8a24 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,68 @@ # Hackathon-Python -Repository for python submissions for Zense Hackathon 2021 -You have to make your python submission pull request to this repository. -Message from Vikas Yadav: Founder of Zense +**#Amazon Price Tracker** -Hi folks, +A python-based project which tracks the price of an item on amazon and sends a pop-up notification on our phone when the price of the item drops below the desired price. +The code runs an infinite loop which breaks only when the price of the item drops below the desired price. +The function which checks the price drop runs after a specific amount of time (We have set it as 1 Hour). -Very happy to see this hackathon happening again. While on campus I loved being part of events like these. A lot of my interests developed as side effects of these events. With that in mind and to encourage the spirit of innovation - I would like to announce a bonus prize of Rs 5000 from my side for the idea which I find the best. In case it's difficult to decide a single winner - please don't mind if I split the prize into two. +Keeping track of price of products in the online sites is not an easy task. Price of products keep on fluctuating and we receive huge discounts during some days of festivals. So, this project helps us by keeping track of price of a product and helps us in buying it at an affordable price. -Parameters I am going to judge you on: -- Feasibility of the idea -- Completeness of the implementation -- Effort you put in -- Impact of the idea +This project tracks just one product at a time (Which can be listed as one of its limitations). -Some potential ideas you can think of: -- Automate a mundane task which you might have to everyday using python -- Explore the python ecosystem to find some amazing libraries - use it to solve a real-world problem around you -- Or just make something cool +The same idea can further be developed and be used to keep a track of stock market. Tracking the price of Bitcoin, Gold or even the drops and gains in share markets. It helps the user buy and sell stocks at the right time. -And it's not just about the award, if you are interested after the hackathon to pursue your idea further I would be happy to mentor. +**Screen Shots:** -Regards, -Vikas +**#When the Price of the item reaches below your desired Price:** +![](Screenshots/2.png) + +#Notification on our phone +![](Screenshots/2(2).png) + + + +**#When the Price of the item is above your desired Price:** + +#Code runs infinitely (Loops is executed again after specified time) and stops only when the price drops. +![](Screenshots/1.png) + + +#No Notification +![](Screenshots/1(1).png) + + +**Installation and Running of the Program** + +Before running the program, you will need to install a few modules and a mobile app. + +First open your command prompt and install 3 modules by the following commands: + +pip install beautifulsoup4 + +pip install requests + +pip install pushbullet.py + +(On Python3 use pip3) + +Now you should install Pushbullet App on your phone and sign in to it (By your Google Account or any other means) and allow the app to show notifications. + +Now open the link of product you want to track on Amazon and copy its URL and initialise it to the **URL** variable defined as a global variable at the top of the program +Also set your desired price for the product you are tracking in the **desired_price** variable. + +Now open site of pushbullet (https://www.pushbullet.com/) and sign in with the same account which you used to login on your phone. You will be able to see your phone on the devices tab. +Now go to Settings->Account. +There under the heading of Access Token you will see an option to "Create Access Token". Copy the generated token and initialize it to the **API_KEY** variable on the code. + +![](Screenshots/pushbullet.png) + +Now just run the code on your terminal by python Amazon_Price_Tracker.py (or python3 Amazon_Price_Tracker.py) +The loop which checks the price runs every 60 mins. So, the price is checked every hour and gives notification on phone if the price dropped. Else displays "Price of the Product is still more than the Desired Price." on your terminal. + + +**YOUTUBE LINK OF DEMO** + +https://youtu.be/gTb-Gt7MXqE diff --git a/Screenshots/1(1).png b/Screenshots/1(1).png new file mode 100644 index 0000000..e32a697 Binary files /dev/null and b/Screenshots/1(1).png differ diff --git a/Screenshots/1.png b/Screenshots/1.png new file mode 100644 index 0000000..f635a09 Binary files /dev/null and b/Screenshots/1.png differ diff --git a/Screenshots/2(2).png b/Screenshots/2(2).png new file mode 100644 index 0000000..0e7a5a8 Binary files /dev/null and b/Screenshots/2(2).png differ diff --git a/Screenshots/2.png b/Screenshots/2.png new file mode 100644 index 0000000..49753e0 Binary files /dev/null and b/Screenshots/2.png differ diff --git a/Screenshots/pushbullet.png b/Screenshots/pushbullet.png new file mode 100644 index 0000000..94aa9ed Binary files /dev/null and b/Screenshots/pushbullet.png differ