Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amazon Price Tracker #6

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fb1faff
Add files via upload
SougandhKrishna Mar 21, 2021
22b3acc
Delete price_tracker_timed.py
SougandhKrishna Mar 21, 2021
d18e415
Add files via upload
SougandhKrishna Mar 21, 2021
b4a09c3
Add files via upload
SougandhKrishna Mar 21, 2021
b552136
Delete Picture1.png
SougandhKrishna Mar 21, 2021
188fdfa
Delete Screenshot_20210321-183511_One UI Home.jpg
SougandhKrishna Mar 21, 2021
9bb187c
Delete Picture2.png
SougandhKrishna Mar 21, 2021
e6894a2
Delete Screenshot_20210321-183607_One UI Home.jpg
SougandhKrishna Mar 21, 2021
647ca92
Add files via upload
SougandhKrishna Mar 21, 2021
0383385
Add files via upload
SougandhKrishna Mar 21, 2021
93aed0e
Update README.md
SougandhKrishna Mar 21, 2021
2134fbb
Update README.md
SougandhKrishna Mar 21, 2021
69a20ae
Update README.md
SougandhKrishna Mar 21, 2021
f87f640
Update Amazon_Price_Tracker.py
SougandhKrishna Mar 21, 2021
4c724e0
Update README.md
SougandhKrishna Mar 21, 2021
874910f
Update README.md
SougandhKrishna Mar 21, 2021
d5ef417
Update README.md
SougandhKrishna Mar 21, 2021
f370614
Update README.md
SougandhKrishna Mar 21, 2021
5808149
Update README.md
SougandhKrishna Mar 21, 2021
2946473
Update README.md
SougandhKrishna Mar 21, 2021
982798c
Add files via upload
SougandhKrishna Mar 21, 2021
3e235be
Add files via upload
SougandhKrishna Mar 21, 2021
a0576b9
Delete PROJECT REPORT.docx
SougandhKrishna Mar 21, 2021
96922fa
Update Amazon_Price_Tracker.py
kernelpanic77 Mar 21, 2021
8e8ae40
Added one more id which contained price
SougandhKrishna Mar 22, 2021
a983567
Update README.md
SougandhKrishna Mar 22, 2021
3175c06
Update README.md
SougandhKrishna Mar 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions Amazon_Price_Tracker.py
Original file line number Diff line number Diff line change
@@ -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()
Binary file added PROJECT REPORT.pdf
Binary file not shown.
75 changes: 58 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Binary file added Screenshots/1(1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/2(2).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/pushbullet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.