Skip to content

Instantly share code, notes, and snippets.

@c0d3x27
Last active April 2, 2022 03:37
Show Gist options
  • Save c0d3x27/9aa836cf000248e13fdcaafeaa87fd0e to your computer and use it in GitHub Desktop.
Save c0d3x27/9aa836cf000248e13fdcaafeaa87fd0e to your computer and use it in GitHub Desktop.
Amazon python bot
import requests
from bs4 import BeautifulSoup
import smtplib
import time
frommail = '@gmail.com'
passwd = 'dbxnbknpiqbsosoi'
tomail = '@hotmail.com'
URL = 'https://www.amazon.com/Apple-MacBook-13-inch-Storage-Keyboard/dp/B0881ZF6WP/ref=sr_1_1?dchild=1&keywords=mac+pro&sr=8-1'
headers = {"User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 9.10; rv:69.0) Gecko/20100101 Firefox/68.0'}
def analyze_price():
app = requests.get(URL, headers=headers)
scrapper = BeautifulSoup(app.content, 'html.parser')
print(scrapper.prettify())
title = scrapper.find(id="productTitle").get_text()
price = scrapper.find(id="priceblock_ourprice").get_text()
StrToFloat_price = float(price[1:6].replace(',' , '.'))
if(StrToFloat_price < 1.600):
send_notification()
print(StrToFloat_price)
print(title.strip())
def send_notification():
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(frommail, passwd)
subject = 'Low price found!'
body = 'Here is the Amazon item link: \n\n' + URL
msg = 'Subject: {}\n\n{}'.format(subject, body)
server.sendmail(frommail, tomail, msg)
print('Notification has been sent successfully')
server.quit()
while True:
analyze_price()
time.sleep(60*60*24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment