Skip to content

Commit 05438dc

Browse files
committed
Modified amazonprice.py to latest scraping parameters, also added the function to send whatsapp message along with email
1 parent 2717a2c commit 05438dc

File tree

2 files changed

+21
-34
lines changed

2 files changed

+21
-34
lines changed

Amazon-Price-Tracker/amazonprice.py

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
from bs4 import BeautifulSoup
33
import time
44
import smtplib
5+
import pywhatkit
6+
import datetime
57

68
# header = {
7-
# "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
9+
# "
10+
# Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
11+
# "
812
# }
913

10-
# Url = "https://www.amazon.in/Apple-AirPods-Wireless-Charging-Case/dp/B07QDRYVCZ/ref=sr_1_1_sspa?crid=2O0YQXVBL4T86&dchild=1&keywords=airpods&qid=1601031081&sprefix=airpod%2Caps%2C615&sr=8-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUFPVUpPNUNIQUE1RUUmZW5jcnlwdGVkSWQ9QTAxNzI3NjJPNlg3OTJFSTVSOE8mZW5jcnlwdGVkQWRJZD1BMDg1MTYzNjJSRUw4VFVKQzQ1TDkmd2lkZ2V0TmFtZT1zcF9hdGYmYWN0aW9uPWNsaWNrUmVkaXJlY3QmZG9Ob3RMb2dDbGljaz10cnVl"
14+
# Url = "
15+
# https://www.amazon.in/Apple-Original-MMTN2ZM-Lightning-Connector/dp/B01M1EEPOB/ref=sr_1_1?crid=XFITOYOGI999&keywords=airpods+apple&qid=1685422019&s=electronics&sprefix=airpods+appl%2Celectronics%2C458&sr=1-1
16+
# "
1117

1218
# get your browser information by searching "my user agent"
1319
user_agent = input("Enter your User-Agent string here\n")
@@ -20,6 +26,11 @@
2026
# print(soup)
2127

2228

29+
def message_sending(phone_number,title):
30+
now = datetime.datetime.now()
31+
message = f"Price of {title} is fallen below the threshold amount. Click on the link below to buy the product!!!\n\n"
32+
pywhatkit.sendwhatmsg(phone_number, message, now.hour, now.minute + 1)
33+
2334
def mail_sending(mail_id, title, password):
2435
server_mail = "smtp.gmail.com"
2536
port = 587
@@ -37,53 +48,28 @@ def mail_sending(mail_id, title, password):
3748
def check_price():
3849
title = soup.find(id="productTitle").get_text().strip()
3950
try:
40-
price = soup.find(
41-
id="priceblock_ourprice_row").get_text().strip()[:20].replace(
42-
'₹', '').replace(' ', '').replace('Price:', '').replace(
43-
'\n', '').replace('\xa0',
44-
'').replace(',', '').replace('Fu', '')
51+
price = price = soup.find('span', class_='a-price-whole').text
52+
price = price[:len(price)-1]
4553

4654
except:
47-
try:
48-
price = soup.find(
49-
id="priceblock_dealprice").get_text().strip()[:20].replace(
50-
'₹', '').replace(' ', '').replace('Price:', '').replace(
51-
'\n', '').replace('\xa0',
52-
'').replace(',',
53-
'').replace('Fu', '')
54-
55-
except:
56-
try:
57-
price = soup.find(
58-
id="priceblock_ourprice").get_text().strip()[:20].replace(
59-
'₹',
60-
'').replace(' ', '').replace('Price:', '').replace(
61-
'\n',
62-
'').replace('\xa0',
63-
'').replace(',', '').replace('Fu', '')
64-
65-
except:
66-
price = soup.find(id="priceblock_ourprice_lbl").get_text(
67-
).strip()[:20].replace('₹', '').replace(' ', '').replace(
68-
'Price:',
69-
'').replace('\n',
70-
'').replace('\xa0',
71-
'').replace(',',
72-
'').replace('Fu', '')
55+
print("Object out of stock or removed")
56+
return
7357

74-
fixed_price = float(price)
58+
fixed_price = float(price.replace(",", ""))
7559
print(title)
7660
print(f'The current price is {fixed_price}')
7761
y_price = (input('Enter the price you wish to get the product at:'))
7862
your_price = y_price.replace(',', '')
7963
mail_id = input("Please enter your email id: ")
8064
password = input("Enter your app password here: ")
65+
phone_number = input("Please enter your phone number: ")
8166
print(
8267
"Thank You! You'll receive an email as soon as the price of product drops...!"
8368
)
8469
# print(price)
8570
if fixed_price <= float(your_price):
8671
mail_sending(mail_id, title, password)
72+
message_sending(phone_number, title)
8773
exit()
8874
else:
8975
pass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://www.amazon.in/Apple-Original-MMTN2ZM-Lightning-Connector/dp/B01M1EEPOB/ref=sr_1_1?crid=XFITOYOGI999&keywords=airpods+apple&qid=1685422019&s=electronics&sprefix=airpods+appl%2Celectronics%2C458&sr=1-1

0 commit comments

Comments
 (0)