Building an Amazon Price Tracker with Python and WayScript

๐๐๐๐๐๐ ๐ก๐๐๐๐
Search for a command to run...

๐๐๐๐๐๐ ๐ก๐๐๐๐
No comments yet. Be the first to comment.
I'm a Graduate student at UT Arlington. I always feel that taking care of both physically and mentally are essential to our success. So, I start my daily routine at Fitness Recreation Center (gym) and registering slots daily is a hassle and due to co...

You might have seen some people using completely different source labels. Well, today we will see how to change the Twitter source label First, we need to have a Twitter developer account, if you don't have. 1) Just navigate to Twitter Developer web...

We all know, Artificial Intelligence (AI) is one of the most transformative tech evolutions of our times. Well, if you still not aware of what AI is? It is the simulation of human intelligence in machines that are programmed to think like humans and ...

I'm a Indian and I recently moved to the USA to pursue my Master's degree at UT Arlington. So I need to carry some essential documents digitally like passport, health reports and other Government id's to be on the safer side and I don't want others t...

In Machine Learning classification problems, there are often too many factors on the basis of which the final classification is done. These factors are basically variables called features. The higher the number of features, the harder it gets to visu...

Hi Well, Today we will discuss How to built Amazon Price Tracker by scraping the price details and scheduling with WayScript
Lemme tell you the real reason to build this ;) I'm a foodie I love Nutella ๐คค but due to this pandemic, I couldn't find Nutella near me in any local stores. So I thought to order it in Amazon but the prices are damn high and prices are fluctuating too... then I started to build a tracker which notifies me whenever the price goes down the tracking price.
We gonna create a python script which uses request and beautifulSoup module to scrape the data and scheduling the script to run every hour either with Serverless AWS Lambda or WayScript but AWS Lambda is not my cup of tea. So I built using WayScript.
We will discuss this process in 2 phases. Phase I : Scraping the product details Phase II : Scheduling the script to run every hour
Step 1: Create an excel sheet with urls and Tracking Price

Step 2: import necessary packages/module
import requests
import bs4
import pandas as pd
Request - The requests module allows you to send HTTP requests using Python bs4 - Beautiful Soup is a library that makes it easy to scrape information from web pandas - pandas is a fast and powerful used for data analysis. we are faking ourselves as a Firefox user to avoid restrictions.
HEADERS = ({'User-Agent':
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36',
'Accept-Language': 'en-US, en;q=0.5'})
Step 3: Building Python Script Here is the tracker function which takes parameters URL and TrackingPrice and adds the details of the product when it is less or than equal to TrackingPrice
def tracker(url,TrackingPrice):
res = requests.get(url,headers=HEADERS)
soup = bs4.BeautifulSoup(res.content, features='lxml')
# to prevent script from crashing when there isn't a price for the product
try:
title = soup.find(id="productTitle").get_text().strip()
amount = float(soup.find(id='priceblock_ourprice').get_text().replace("โน","").replace("$","").strip())
if amount<=TrackingPrice:
offer.append("You got a offer on the {0} for {1}. Check out the product {2}".format(title,amount,url))
except:
offer.append("Couldn't get details about product")
Source Code:
import requests
import bs4
import pandas as pd
HEADERS = ({'User-Agent':
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36',
'Accept-Language': 'en-US, en;q=0.5'})
offer=[]
def tracker(url,TrackingPrice):
res = requests.get(url,headers=HEADERS)
soup = bs4.BeautifulSoup(res.content, features='lxml')
# to prevent script from crashing when there isn't a price for the product
try:
title = soup.find(id="productTitle").get_text().strip()
amount = float(soup.find(id='priceblock_ourprice').get_text().replace("โน","").replace("$","").strip())
if amount<=TrackingPrice:
offer.append("You got a offer on the {0} for {1}. Check out the product {2}".format(title,amount,url))
except:
offer.append("Couldn't get details about product")
df=pd.read_csv("https://docs.google.com/spreadsheets/d/1AzJ93zR6--4vwl81W3v0FHyZ_bFMkFYRxOSjodJu_Qw/export?format=csv")
for i in range(0,len(df["URL"])):
tracker(df["URL"][i],df["TrackingPrice"][i])
outputs["message"]=offer
Output:
we're done with our python script
Now let's move to Phase II
Phase II:
I already told you can schedule this script either by using AWS Lambda or any other cloud computing services as I'm not familar with AWS. I'm going with WayScript
And this WayScript provide wide range of packages to interact with services Ex:
Step 1: Open WayScript
Packages used for this scheduling:
Click here to check my configuration in WayScript