-
Notifications
You must be signed in to change notification settings - Fork 0
/
amazon_prices.py
74 lines (53 loc) · 1.86 KB
/
amazon_prices.py
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
65
66
67
68
69
70
71
72
73
74
# Amazon price tracker
import requests
from bs4 import BeautifulSoup
import smtplib
import time
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0'}
amazon_items = []
notif_prices = []
def send_email(itemLink, min, adress):
# setting the connection
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('[email protected]', '')
# email Content
subject = 'Price felling down'
body = 'Hello, The price of the Amazon item ' + itemLink + ' is now less than ' + str(min) + ' euros.' + '\nGo check it out.'
# sending the email
email = f'Subject:{subject}\n\n{body}'
server.sendmail('automaticmail05.gmail.com', adress, email)
print('Email Sent !')
server.quit()
def Track_price(itemLink, min, adress):
page = requests.get(itemLink, headers = headers)
soup = BeautifulSoup(page.content, 'html.parser')
price = soup.find(id = 'priceblock_ourprice').get_text()
price = int(price[:-5])
if price < min:
send_email(itemLink, min, adress)
def get_item():
item = input('Paste the amazon link here :')
amazon_items.append(item)
def get_min_price():
min = float(input("What price you want to get notification for ? "))
notif_prices.append(min)
def get_links():
add = True
while add:
get_item()
get_min_price()
choice = input("Do you want to add another item ? [y/n]")
if choice == 'N' or choice == 'n':
add = False
print('The items are registered, you will receive an email if the prices drops down.')
email_adress = input('Type your email adress : ')
get_links()
n = len(amazon_items)
# main loop
while True:
for i in range(n):
Track_price(amazon_items[i], notif_prices[i], email_adress)
time.sleep(1200*12)