2
2
from bs4 import BeautifulSoup
3
3
import time
4
4
import smtplib
5
+ import pywhatkit
6
+ import datetime
5
7
6
8
# 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
+ # "
8
12
# }
9
13
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
+ # "
11
17
12
18
# get your browser information by searching "my user agent"
13
19
user_agent = input ("Enter your User-Agent string here\n " )
20
26
# print(soup)
21
27
22
28
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
+
23
34
def mail_sending (mail_id , title , password ):
24
35
server_mail = "smtp.gmail.com"
25
36
port = 587
@@ -37,53 +48,28 @@ def mail_sending(mail_id, title, password):
37
48
def check_price ():
38
49
title = soup .find (id = "productTitle" ).get_text ().strip ()
39
50
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 ]
45
53
46
54
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
73
57
74
- fixed_price = float (price )
58
+ fixed_price = float (price . replace ( "," , "" ) )
75
59
print (title )
76
60
print (f'The current price is { fixed_price } ' )
77
61
y_price = (input ('Enter the price you wish to get the product at:' ))
78
62
your_price = y_price .replace (',' , '' )
79
63
mail_id = input ("Please enter your email id: " )
80
64
password = input ("Enter your app password here: " )
65
+ phone_number = input ("Please enter your phone number: " )
81
66
print (
82
67
"Thank You! You'll receive an email as soon as the price of product drops...!"
83
68
)
84
69
# print(price)
85
70
if fixed_price <= float (your_price ):
86
71
mail_sending (mail_id , title , password )
72
+ message_sending (phone_number , title )
87
73
exit ()
88
74
else :
89
75
pass
0 commit comments