Skip to content

Commit d28525f

Browse files
committed
Day 47
- Create an Automated Amazon Price Tracker - Changed Constants name
1 parent b241a5a commit d28525f

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
- [Day 44](https://github.com/a092devs/100-days-of-python/tree/master/day044) - Intermediate CSS
5353
- [Day 45](https://github.com/a092devs/100-days-of-python/tree/master/day045) - Web Scraping with BeautifulSoup
5454
- [Day 46](https://github.com/a092devs/100-days-of-python/tree/master/day046) - Create a Spotify Playlist Using The Musical Time Machine
55+
- [Day 47](https://github.com/a092devs/100-days-of-python/tree/master/day047) - Create an Automated Amazon Price Tracker
5556

5657
## ⚙ Tools and Technologies Covered
5758
- Python 3

day033/iss_overhead/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import time
55
import smtplib
66

7-
MY_EMAIL = "my_email_was_here"
7+
FROM_EMAIL = "my_email_was_here"
88
PASSWORD = "my_pass_was_here"
99
MY_LAT = 23.603900
1010
MY_LONG = 87.117700
@@ -49,8 +49,8 @@ def is_night():
4949
if is_iss_overhead() and is_night():
5050
with smtplib.SMTP("smtp.mail.yahoo.com", 587) as connection:
5151
connection.starttls()
52-
connection.login(MY_EMAIL, PASSWORD)
52+
connection.login(FROM_EMAIL, PASSWORD)
5353
connection.sendmail(
54-
from_addr=MY_EMAIL,
54+
from_addr=FROM_EMAIL,
5555
to_addrs="a092devs@email.com",
5656
msg="Subject:Look Up👆🏼\n\nThe ISS is above you in the sky!".encode("utf-8"))

day040/notification_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
BOT_TOKEN = environ.get("BOT_TOKEN")
99
CHAT_ID = environ.get("CHAT_ID")
1010
MAIL_PROVIDER_SMTP_ADDRESS = "smtp.mail.yahoo.com"
11-
MY_EMAIL = environ.get("MY_EMAIL")
12-
MY_PASSWORD = environ.get("MY_PASSWORD")
11+
FROM_EMAIL = environ.get("FROM_EMAIL")
12+
FROM_PASSWORD = environ.get("FROM_PASSWORD")
1313

1414
class NotificationManager:
1515
def telegram_bot_send_text(self, bot_message):
@@ -22,10 +22,10 @@ def telegram_bot_send_text(self, bot_message):
2222
def send_emails(self, emails, message, google_flight_link):
2323
with smtplib.SMTP(MAIL_PROVIDER_SMTP_ADDRESS, 587) as connection:
2424
connection.starttls()
25-
connection.login(MY_EMAIL, MY_PASSWORD)
25+
connection.login(FROM_EMAIL, FROM_PASSWORD)
2626
for email in emails:
2727
connection.sendmail(
28-
from_addr=MY_EMAIL,
28+
from_addr=FROM_EMAIL,
2929
to_addrs=email,
3030
msg=f"Subject:New Low Price Flight!\n\n{message}\n{google_flight_link}".encode('utf-8')
3131
)

day046/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
CLIENT_ID = environ.get("CLIENT_ID")
1010
CLIENT_SECRET = environ.get("CLIENT_SECRET")
1111

12-
date = input("Which day do you want to travel to? Type the date in this format: YYYY-MM-DD: ")
12+
date = input("Which day do you want to travel to? Type the date in this format YYYY-MM-DD: ")
1313

1414
URL = f"https://www.billboard.com/charts/hot-100/{date}/"
1515
response = requests.get(URL)

day047/main.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import requests
2+
import smtplib
3+
from bs4 import BeautifulSoup
4+
from os import environ
5+
from dotenv import load_dotenv
6+
7+
load_dotenv('config.env', override=True)
8+
9+
FROM_EMAIL = environ.get("FROM_EMAIL")
10+
FROM_PASSWORD = environ.get("FROM_PASSWORD")
11+
TO_EMAIL = environ.get("TO_EMAIL")
12+
13+
URL = "https://www.amazon.com/dp/B075CYMYK6"
14+
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) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.58"
18+
}
19+
20+
response = requests.get(URL, headers=http_headers)
21+
soup = BeautifulSoup(response.text, 'html.parser')
22+
23+
price = float(soup.find(name="span", class_="a-offscreen").getText()[1:])
24+
product_name = " ".join(soup.find(
25+
name="span", class_="a-size-large product-title-word-break").getText().split())
26+
27+
if price < 10.00:
28+
with smtplib.SMTP("smtp.mail.yahoo.com", 587) as connection:
29+
connection.starttls()
30+
connection.login(FROM_EMAIL, FROM_PASSWORD)
31+
connection.sendmail(from_addr=FROM_EMAIL,
32+
to_addrs=TO_EMAIL,
33+
msg=f"Subject: Price Drop Alert!\n\n{product_name} is now available in ${price}\n\nVisit: {URL}".encode('utf-8')
34+
)

0 commit comments

Comments
 (0)