-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprice_tracker.py
More file actions
64 lines (51 loc) · 1.68 KB
/
price_tracker.py
File metadata and controls
64 lines (51 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Step 1
"""Find link to item you want to track"""
# Step 2
"""Generate email that will be used for notification"""
# Step 3
"""
Create API header
Use requests to get web info
"""
# Step 4
"""
Make soup
"""
# Step 5
"""Send email"""
import requests
from bs4 import BeautifulSoup
# import lxml
import smtplib as smtp
import os
from dotenv import load_dotenv
# loading environment variables
load_dotenv()
PRODUCT_URL = "https://www.jumia.com.gh/ps5-console-825gb-white-playstation-mpg441043.html"
test_email = os.environ.get('MY_EMAIL')
test_password = os.environ.get('MY_PASSWORD')
# making a request to page
header = {
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
}
response = requests.get(url=PRODUCT_URL, headers=header)
web_data = response.text
# Making Soup
soup = BeautifulSoup(web_data, "html.parser")
# print(soup.title)
# Extracting the product title and price
product_title = soup.find(name="h1", class_="-fs20 -pts -pbxs").text
product_price = float(soup.find(name="span", class_="-b -ltr -tal -fs24").text.split(" ")[1].replace(",", ""))
# print(product_price)
# Sending the email id product price less than specified price
if product_price < 7000:
with smtp.SMTP(host="smtp.gmail.com") as connection:
connection.starttls()
connection.login(user=test_email, password=test_password)
connection.sendmail(
from_addr=test_email,
to_addrs="chukwuexcel14@gmail.com",
msg=f"Subject: Jumia Price Alert!\n\n{product_title} is now {product_price}. \n \
Hurry to {PRODUCT_URL} to get it!"
)