-
Notifications
You must be signed in to change notification settings - Fork 0
/
source
46 lines (30 loc) · 1.84 KB
/
source
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
import requests
from bs4 import BeautifulSoup
import smtplib
URL = 'https://www.amazon.com/Gaming-i7-8750H-Processor-GeForce-Windows/dp/B07GWX25CV/ref=bmx_2/139-0467873-6925201?_encoding=UTF8&pd_rd_i=B07GWX25CV&pd_rd_r=023fc008-ff44-4063-939f-53e711642133&pd_rd_w=g9Smx&pd_rd_wg=L8Ovh&pf_rd_p=806524e0-5994-4c0d-9d36-11f6132400bc&pf_rd_r=C6PVGAGE8Q7PP2A02W25&psc=1&refRID=C6PVGAGE8Q7PP2A02W25'
headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0'}
def check_price():
page = requests.get(URL, headers=headers)
soup1 = BeautifulSoup(page.content, 'html.parser')
soup2 = BeautifulSoup(soup1.prettify(), "html.parser")
title = soup2.find(id = "productTitle").get_text() # you can change the id value depending on the value you want to retrive
price = soup2.find(id = "priceblock_ourprice").get_text()
converted_price = float(price[1:].replace(',', ''))
if(converted_price < 1700.00):
send_mail()
print(converted_price)
def send_mail():
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('your@email', 'Google generated password') #Go tp https://myaccount.google.com/apppasswords to generated a password for your device (eg.Windows)
subject = 'Prices went down!'
body = 'Check it out here https://www.amazon.com/Gaming-i7-8750H-Processor-GeForce-Windows/dp/B07GWX25CV/ref=bmx_2/139-0467873-6925201?_encoding=UTF8&pd_rd_i=B07GWX25CV&pd_rd_r=023fc008-ff44-4063-939f-53e711642133&pd_rd_w=g9Smx&pd_rd_wg=L8Ovh&pf_rd_p=806524e0-5994-4c0d-9d36-11f6132400bc&pf_rd_r=C6PVGAGE8Q7PP2A02W25&psc=1&refRID=C6PVGAGE8Q7PP2A02W25'
msg = f"Subject: {subject}\n\n{body}"
server.sendmail(
from_addr='your@email',
to_addrs='mail@you_want_to_receive_msg',
msg=msg)
print('Mail Sent')
check_price()