0% found this document useful (0 votes)
2 views

pyth project

The project report details the development of an 'Amazon Product Availability Checker' using Python, which tracks product availability on Amazon and notifies users via email when products are in stock. The application utilizes various Python modules, including lxml for HTML parsing, requests for making HTTP requests, and smtplib for sending emails. Users provide an Amazon Standard Identification Number (ASIN) to monitor specific products, and the system checks their availability at regular intervals, sending notifications accordingly.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

pyth project

The project report details the development of an 'Amazon Product Availability Checker' using Python, which tracks product availability on Amazon and notifies users via email when products are in stock. The application utilizes various Python modules, including lxml for HTML parsing, requests for making HTTP requests, and smtplib for sending emails. Users provide an Amazon Standard Identification Number (ASIN) to monitor specific products, and the system checks their availability at regular intervals, sending notifications accordingly.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

B.L.D.E.A’s VACHANA PITAMAHA DR.P.G.

HALAKATTI
COLLEGE OF ENGINEERING AND TECHNOLOGY,
VIJAYAPUR-586 103

PROJECT REPORT ON:


“Amazon Product Availability Checker Using Python.”

SUBMITTED BY:
Akanksha. Rudragoudar - 2BL20CS013
Aishwarya. Hirolli - 2BL20CS010
Anjana. Hiroli – 2BL20CS022

UNDER THE SUPERVISION OF:


Prof. Dakshayani. Ijeri
Prof. of CSE
TABLE OF CONTENT:

1. Abstract

2. Introduction

3. Architecture / Methodology / Flow Chart

4. Implementation

5. System Model Snapshots


ABSTRACT:
As we know Python is a multi-purpose language and widely used for scripting. It’s usage is
not just limited to solve complex calculations but also to automate daily life task. Just like
tracking or checking the availability of the products in the online shopping stores. Python has
many modules that facilitate this application. This application had made the life of people so
easy that we can check the availability of the products within a touch, Instead of physically
going to stores and markets for buying things.

INTRODUCTION:
The objective of this project is to track or check the availability of any product from Amazon
and grab the deal when the product is in stock and inform the user regarding the availability
of product through email. And if the product is not available currently then no email will be
sent to the user. Asin Id should be provided by the user for the product he wants to keep
track of. Email consists of the current status of the availability of the product and along with
the Asin Id of the product which user had provided.
Asin Id - Amazon Standard Identification Number is a 10 - character
alphanumeric unique identifier assigned by Amazon for product identification within the
Amazon organization.
ARCHITECTURE:

Start

User should provide


his email Id

User should provide


Asin Id of the product
he wants to buy

Yes No
Checks for
availability of
the product

Returns Product in Returns Product Not


Stock in Stock

Sends mail to the user


No email will be sent
regarding availability
of the product

End
IMPLEMENTATION:
The various modules and built-in functions that have been used in the respective Python
project are as follows –

Modules:
1. lxml -
lxml module is a very unique and special module of Python. It provides powerful API
for parsing HTML content. This module can be installed by :
pip install lxml
in the command prompt.
The online content that has been requested through requests.get() to the User Agent will
be in the form of html content, So to parse the html content we have used
html.fromstring()
which returns document_fromstring or fragment_fromstring, based on whether the
string looks like a full document or just a fragment.

2. requests -
requests module has several built-in methods to make http requests to specified URL
using get, post, put, patch or head requests. A http request is meant either to retrieve
data from a specified URL or to push data to a server. This module can be installed by:
pip install requests
in the command prompt.
In our project we have used get() to retrieve information from the given server using a
given URL. The get() send the encoded user information appended to the page request.

3. time –
As the name suggests Python time module allows to work with time in Python. It allows
functionality like getting the current time, pausing the program from executing etc. This
module can be installed by:
pip install time
in the command prompt.
This module has a built-in method called sleep() which suspends execution for the given
number of seconds, minutes or hours.
Sometimes there is a need to halt the flow of the program so that several other executions
can take place or because of continuous checks in milliseconds or few seconds blocks
the request. This provides an accurate and flexible way to halt the flow of code for any
period of time.
4. schedule –
schedule is in-process scheduler for periodic jobs that use the builder pattern for
configuration, schedule lets us run Python functions (or any other callable) periodically
at pre-determined intervals using a simple, human-friendly syntax. This module can be
installed by:
pip install schedule
in the command prompt.
There are many scheduler class for this schedule module in our Python project we are
using
schedule.run_pending()
here run_pending() is the scheduler class it calls run_pending() on the default scheduler
instance. Run all jobs that are scheduled to run. We are also using another scheduler
class named
schedule.ever(interval=1)
it calls on every default scheduler instance, schedule a new periodic job. There are many
basic methods for schedule,job one of which is used in our project is
do(job_func)
it specifies the job_func that should be called every time the job runs.

5. smtplib –
Python offers a library to send emails “SMTP lib”. smtplib creates a Simple Mail
Transfer Protocol client session object which is used to send emails to any valid email
id on the internet. The port number used here is ‘587’. This module can be installed by:
pip install smtplib
After importing this module it creates a session, will be using its instance SMTP to
encapsulate an SMTP connection.
s = smtplib.SMTP(‘smtp.gmail.com’,587)
here first parameter is the server location and second parameter is port to use. For gmail
we use port number is 587. For security reasons, we will put the SMTP connection in
TLS mode i.e., Transport Layer Security encrypts ll the SMTP commands.
For security and authentication we need to pass our Gmail account
credentials in the login instance. The compiler will show an authentication error if we
enter an invalid email id or password.
Store the message we need to send in a variable (in our project the
variable is “content”). Using the sendmail() instance, send you content or message,
sendmail() uses three parameters : sender_email_id, receiver_email_id and
message_to_br_sent. In our project the parameters are like:
s.sendmail(GMAIL_USERNAME, recipient, content)
Note that parameters need to be in same sequence.
Below is the implementation of the respective project:
Source code –

# Python script for Amazon product availability checker


# importing libraries
from lxml import html
import requests
from time import sleep
import time
import schedule
import smtplib

# Email id for who want to check availability


receiver_email_id = "EMAIL_ID_OF_USER"

def check(url):
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36'}

# adding headers to show that you are


# a browser who is sending GET request
page = requests.get(url, headers = headers)
for i in range(20):
# because continuous checks in
# milliseconds or few seconds
# blocks your request
sleep(3)

# parsing the html content


doc = html.fromstring(page.content)
# checking availability
XPATH_AVAILABILITY = '//div[@id ="availability"]//text()'
RAw_AVAILABILITY = doc.xpath(XPATH_AVAILABILITY)
AVAILABILITY = ''.join(RAw_AVAILABILITY).strip() if
RAw_AVAILABILITY else None
return AVAILABILITY

def sendemail(ans, product):


GMAIL_USERNAME = "YOUR_GMAIL_ID"
GMAIL_PASSWORD = "YOUR_GMAIL_PASSWORD"

recipient = receiver_email_id
body_of_email = ans
email_subject = product + ' product availability'

# creates SMTP session


s = smtplib.SMTP('smtp.gmail.com', 587)

# start TLS for security


s.starttls()

# Authentication
s.login(GMAIL_USERNAME, GMAIL_PASSWORD)

# message to be sent
headers = "\r\n".join(["from: " + GMAIL_USERNAME,
"subject: " + email_subject,
"to: " + recipient,
"mime-version: 1.0",
"content-type: text/html"])
content = headers + "\r\n\r\n" + body_of_email
s.sendmail(GMAIL_USERNAME, recipient, content)
s.quit()

def ReadAsin():
# Asin Id is the product Id which
# needs to be provided by the user
Asin = 'B077PWK5BT'
url = "http://www.amazon.in/dp/" + Asin
print ("Processing: "+url)
ans = check(url)
arr = [
'Only 1 left in stock.',
'Only 2 left in stock.',
'In stock.']
print(ans)
if ans in arr:
# sending email to user if
# in case product available
sendemail(ans, Asin)

# scheduling same code to run multiple


# times after every 1 minute
def job():
print("Tracking....")
ReadAsin()
schedule.every(1).minutes.do(job)

while True:

# running all pending tasks/jobs


schedule.run_pending()
time.sleep(1)

RESULT WITH SNAPSHOTS:

Input is the highlighted part in the URL of the product that is called as Asin Id of a product.
When the user provides the Asin id as input the code will run to check if the product that
user wishes to buy is available i.e., in stock or out of stock, and if it is in stock the mail will
be sent to the user to inform that product is in stock.
Product Asin Id (Input)
This is the snapshot of the output that will get when we will run the program if the product is
in stock.

This is the snapshot of mail we will get when the product is in stock, to inform the user that
the product they require is available for them to purchase.
This is the snapshot of the output that will get when we will run the program if the product
has only 1 left in stock.

This is the snapshot of mail we will get when the product has only 1 left in stock, to inform
the user that the product they want to purchase has only 1 left in stock.
This is the snapshot of the output that will get when the Asin Id of product provided by the
user is currently unavailable or out of stock. In this case no email will be sent to the user.

You might also like