Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib,requests, re
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from bs4 import BeautifulSoup
- def sendEmail():
- #Email Account
- email_sender_account = "<email>"
- email_sender_username = "<username>"
- email_sender_password = "<password>"
- email_smtp_server = "<smtp>"
- email_smtp_port = <port>#Email Content
- email_recepients = ["<email>"]
- email_subject = "Black speaker Sale"
- email_body = "The speaker is currently on sale for $" + str(money) + ".Find at " + (url)
- #login to email server
- server = smtplib.SMTP(email_smtp_server,email_smtp_port)
- server.starttls()
- server.login(email_sender_account, email_sender_password)
- #For loop, sending emails to all email recipients
- for recipient in email_recepients:
- print(f"Sending email to {recipient}")
- message = MIMEMultipart('alternative')
- message['From'] = email_sender_account
- message['To'] = recipient
- message['Subject'] = email_subject
- message.attach(MIMEText(email_body, 'html'))
- text = message.as_string()
- server.sendmail(email_sender_account,recipient,text)
- #All emails sent, log out.
- server.quit()
- url = 'https://www.jbhifi.com.au/products/ultimate-ears-boom-3-portable-bluetooth-speaker-night-black'
- res=requests.get(url)
- res.raise_for_status() #checks to see if the site is downloaded
- soup =BeautifulSoup(res.text,'html.parser')
- mySpan = soup.find_all("span", {"class": "sale"})
- if not mySpan:
- print("Item is not on sale yet")
- #I have no idea what i am doing for this for loop. None.
- for price in mySpan:
- currency, money = price.contents[:2]
- money=int(money)
- #print(money)
- if money <= int(180):
- sendEmail()
- else:
- print('Not cheaper')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement