1+ from bs4 import BeautifulSoup
2+ import requests
3+ import os
4+ import smtplib
5+ import datetime
6+ from dotenv import load_dotenv
7+
8+ load_dotenv ()
9+ date = datetime .datetime .now ().strftime ("%d/%m/%Y" )
10+
11+ # static url to get the price
12+ url = "https://appbrewery.github.io/instant_pot/"
13+
14+ # live url to get the price which is dyanmaic hard to parse so i take the static url
15+ live_url = "https://www.amazon.com/dp/B075CYMYK6?psc=1&ref_=cm_sw_r_cp_ud_ct_FM9M699VKHTT47YD50Q6"
16+
17+ # ADD header for look my requests more realistics rather than ai generated
18+ # requests.get(url, params=None, headers=None, cookies=None, auth=None, timeout=None) this is params of requests
19+
20+ # header
21+
22+ header = {
23+ "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" ,
24+ "Accept-Encoding" : "gzip, deflate, br, zstd" ,
25+ "Accept-Language" : "en-US,en;q=0.9,hi;q=0.8" ,
26+ "Dnt" : "1" ,
27+ "Priority" : "u=0, i" ,
28+ "Sec-Ch-Ua" : '"Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141"' ,
29+ "Sec-Ch-Ua-Mobile" : "?0" ,
30+ "Sec-Ch-Ua-Platform" : "Windows" ,
31+ "Sec-Fetch-Dest" : "document" ,
32+ "Sec-Fetch-Mode" : "navigate" ,
33+ "Sec-Fetch-Site" : "cross-site" ,
34+ "Sec-Fetch-User" : "?1" ,
35+ "Upgrade-Insecure-Requests" : "1" ,
36+ "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36" ,
37+ }
38+
39+ response = requests .get (url = live_url ,headers = header )
40+ soup = BeautifulSoup (response .text ,"html.parser" )
41+
42+ # check whether what kind of requests i get
43+ print (soup .prettify ()[:2000 ])
44+
45+ price = soup .find (class_ = "a-price-whole" ).get_text ()
46+
47+ price_without_currency = price .split ("$" )[1 ]
48+
49+ price_as_float = float (price_without_currency )
50+
51+ print (price_as_float )
52+
53+
54+ # Send Email if price less than 100
55+ if price_as_float < 100 :
56+ my_email = os .getenv ("EMAIL" )
57+ password = os .getenv ("PASSWORD" )
58+
59+ with smtplib .SMTP ("smtp.gmail.com" ,port = 587 ) as connection :
60+ connection .starttls ()
61+ connection .login (user = my_email ,password = password )
62+
63+ connection .sendmail (
64+ from_addr = my_email ,
65+ to_addrs = "srnwda@gmail.com" ,
66+ msg = f"Subject:Amazon Price Alert\n \n { price } \n { live_url } \n at the time of { date } "
67+ )
68+
69+ # you can try with static becuase live might not run
0 commit comments