Skip to content

Commit b98a68d

Browse files
authored
Create main.py
1 parent d5a40bb commit b98a68d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Diff for: day47/main.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
import os
4+
from dotenv import load_dotenv
5+
import smtplib
6+
7+
load_dotenv(".env")
8+
MY_EMAIL = os.getenv("MY_EMAIL")
9+
MY_PASSWORD = os.getenv("MY_PASSWORD")
10+
TO_EMAIL = os.getenv("TO_EMAIL")
11+
12+
URL = "https://www.amazon.com/Resistance-INNELO-Workout-Exercise-Stackable/dp/B092HT8TL2/ref=sr_1_2?keywords=" \
13+
"work%2Bfrom%2Bhome%2Bfitness&pd_rd_r=caad6e53-d0a0-417d-a68f-ce8f4b163fda&pd_rd_w=qvoAu&pd_rd_wg=" \
14+
"s58LM&pf_rd_p=d6dae0b5-d3cf-4be0-8934-83385f36bcc9&pf_rd_r=A19XTC1PF3S9R4XDW3BE&qid=1647285684&sr=8-2&th=1"
15+
http_headers = {
16+
"Accept-Language": "en-US,en;q=0.9",
17+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
18+
"Chrome/99.0.4844.51 Safari/537.36",
19+
}
20+
response = requests.get(URL, headers=http_headers)
21+
website_html = response.text
22+
23+
soup = BeautifulSoup(website_html, "html.parser")
24+
25+
price = float(soup.find(name="span", class_="a-offscreen").getText()[1:])
26+
product_name = " ".join(
27+
soup.find(name="span", class_="a-size-large product-title-word-break", id="productTitle").getText().split())
28+
29+
if price < 25.00:
30+
with smtplib.SMTP("smtp.outlook.com") as connection:
31+
connection.starttls()
32+
connection.login(MY_EMAIL, MY_PASSWORD)
33+
connection.sendmail(
34+
from_addr=MY_EMAIL,
35+
to_addrs=TO_EMAIL,
36+
msg=f"Subject: Alert: Amazon Price Tracker\n\n{product_name}\nis now ${price}.\n\n{URL}",
37+
)

0 commit comments

Comments
 (0)