Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 231698e

Browse files
Merge pull request avinashkranjan#555 from Jade9ja/added-flipkart-price-alert
add-flipkart-price-alert-with-changes
2 parents a57b79d + 85d5a3f commit 231698e

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

‎Flipkart-price-alert/README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Flipkart Price Alert
2+
Checks for the price of a desired product periodically.
3+
If the price drops below the desired amount, notifies the user via email.
4+
## Setup Instructions
5+
Type the following to install requirements: (make sure you have python installed)
6+
`pip install -r requirements.txt`
7+
This script requires access to mail credentials inorder to work, follow the steps below to generate the credentials for a limited scope.
8+
## Optional: How to get alternate login credentials:
9+
1) To get app passwords, go to myaccount.google.com/security
10+
2) Make sure you save 2-step verification turned on.
11+
3) Choose app passwords (under signing into google)
12+
4) Then under app choose mail and under platform, choose the device from which you are logged in from.
13+
14+
![](https://devanswers.co/wp-content/uploads/2017/02/my-google-app-passwords.png)
15+
16+
## Usage
17+
1) Run the track.py script. `python track.py`
18+
2) Hope the price drops :).
19+
20+
## Author
21+
[Ea](github.com/jade9ja)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
beautifulsoup4
2+
requests
3+
smtplib

‎Flipkart-price-alert/track.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import requests
2+
from bs4 import BeautifulSoup as bs
3+
import smtplib
4+
import time
5+
headers = {'User-Agent': 'Mozilla/5.0 Chrome/86.0.4240.75'}
6+
7+
def sendMail(title):
8+
'''Send Email'''
9+
server = smtplib.SMTP('smtp.gmail.com', 587)
10+
server.ehlo()
11+
server.starttls()
12+
server.ehlo()
13+
server.login(MY_EMAIL, MY_APP_PASSWORD)
14+
subject = 'Change in price detected for ' + title
15+
print(subject)
16+
body = 'Click the link to go to the product page \n' + PRODUCT_URL
17+
msg = f"Subject: {subject}\n\n{body}"
18+
print(msg)
19+
server.sendmail(MY_EMAIL, RECEIVER_EMAIL, msg)
20+
print('Email Sent')
21+
server.quit()
22+
23+
24+
def priceCheck():
25+
'''Price checking function'''
26+
page = requests.get(PRODUCT_URL, headers=headers)
27+
soup = bs(page.content, 'html.parser')
28+
# title from 'B_NuCI' class
29+
title = soup.find("span", {"class": "B_NuCI"}).get_text()[0:8] + '..'
30+
print(title)
31+
# price from '_30jeq3 _16Jk6d' class,
32+
raw_price = soup.find("div", {"class": "_30jeq3 _16Jk6d"})
33+
# removing unnecessary characters from the price.
34+
price = float(raw_price.get_text()[1:].replace(',', ''))
35+
print(price)
36+
print(THRESHHOLD)
37+
# If the price falls below threshold, send an email
38+
if(price < THRESHHOLD):
39+
sendMail(title)
40+
41+
42+
43+
PRODUCT_URL = input('Enter the product url:')
44+
THRESHHOLD = float(input('Enter the desired price:'))
45+
MY_EMAIL = input('Enter the email address that will be used to send alerts:')
46+
MY_APP_PASSWORD = input('Enter password:')
47+
RECEIVER_EMAIL = input('Enter the receiver email:')
48+
CHECK_AGAIN = int(input('Enter the time between checks in minutes:'))
49+
50+
if (PRODUCT_URL == '' or MY_APP_PASSWORD == '' or MY_EMAIL == '' or RECEIVER_EMAIL == ''):
51+
print('VALUES MISSING! TRY AGAIN')
52+
exit()
53+
while(True):
54+
priceCheck()
55+
time.sleep(CHECK_AGAIN*60)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /